How to get AssetBundleManifest from AssetBundle in Unity3D

旧城冷巷雨未停 提交于 2019-12-24 12:06:41

问题


I have read AssetBundles Document and also tried to get the manifest from the specific assetbundle like the document. I want to get character's manifest but the manifest from the code returns null.

I've changed the AssetBundleManifest at line 5 to character or character.manifest and it is also null:

private IEnumerator LoadAssetBundleManifest()
{
    string assetBundlePath = Application.dataPath + "/../AssetBundles/Android/character";
    AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath); // assetBundle also have data.
    var manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

    print(manifest); // manifest = null

    yield return null;
}

This image is the folder of my asset:

PS. Now, I'm using Unity 2018.1.1f1.


回答1:


you should do like this

void LoadAsserBundle()
{
    AssetBundle manifestAssetBundle = AssetBundle.LoadFromFile(GetAssetBundlePath("StreamingAssets"));
    AssetBundleManifest assetBundleManifest = manifestAssetBundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");

    AssetBundle assetBundle = AssetBundle.LoadFromFile(GetAssetBundlePath("character"));
    Hash128 hash = assetBundleManifest.GetAssetBundleHash(assetBundle.name);
}


来源:https://stackoverflow.com/questions/51280401/how-to-get-assetbundlemanifest-from-assetbundle-in-unity3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!