I’ve been attempting to entry the On Demand Assets in a unity mission for IOS. I adopted the documentation for IOS app thinning, and wrote the next code to load the bundle into an AssetBundle variable:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.iOS;
utilizing System;
public class AssetBundleIterator : MonoBehaviour
{
public string bundleName;
AssetBundle bundle;
bool loadedBundle;
OnDemandResourcesRequest bundleRequest;
void Awake()
{
Initialize();
//StartCoroutine(LoadGameInEditor());
StartCoroutine(LoadBundle());
}
personal IEnumerator LoadBundle()
{
bundleRequest = OnDemandResources.PreloadAsync( new string[] { bundleName } );
yield return bundleRequest;
if (bundleRequest.error != "")
{
errorText.textual content = "ODR request failed: " + bundleRequest.error;
throw new Exception( "ODR request failed: " + bundleRequest.error );
}
string path = bundleRequest.GetResourcePath(bundleName);
bundle = AssetBundle.LoadFromFile( path + bundleName );
bundleRequest.Dispose();
loadedBundle = true;
}
The asset bundles have been assigned their names as their tags.
After I begin the appliance, I can not entry the asset bundle, though bundleRequest didn’t throw any exceptions.
I ought to have the ability to load a file, for instance, a sprite, from the asset bundle utilizing this code:
AssetBundleRequest assetRequest = new AssetBundleRequest();
strive
{
assetRequest = bundle.LoadAssetWithSubAssetsAsync<T>(_assetName);
} catch
{
Debug.LogWarning("AssetBundle Not Discovered");
}
yield return assetRequest;
But it surely doesn’t load something.