I want to load and instantiate asset from my asset bundle, but in unity 5.+ i can do it with code like this: Note: my assetbundle have one asset inside itself, like:
AssetBundle myLoadedAssetBundle;
public string path;
void Start()
{
LoadAssetBundle(path);
}
void LoadAssetBundle(string bundleUrl)
{
myLoadedAssetBundle = AssetBundle.LoadFromFile(bundleUrl);
Debug.Log(myLoadedAssetBundle == null ? "Faild To Load" : "Succesfully Loaded!");
Debug.Log(myLoadedAssetBundle.mainAsset.name);
Instantiate(myLoadedAssetBundle.mainAsset);
}
}
actually even i use
Debug.Log(myLoadedAssetBundle.mainAsset.name);
to log name of mainasset of my assetbundle!
but in unity after 5+ , they say mainasset is obsolete.
my questions is:
1- How can i load asset bundle which don't know the name of asset?
2- How Instantiate or assign sprite which loaded of assetbundle ?