简体   繁体   中英

How to get unity assetbundle manifest?

在此处输入图片说明

Here my code:

AssetBundle ab = AssetBundle.LoadFromFile(Application.dataPath + "/uia.manifest");//get null here
AssetBundleManifest manifest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest");

Have a look at Using AssetBundles Natively in particular the section Loading AssetBundle Manifests where it states

Loading AssetBundle manifests can be incredibly useful. Especially when dealing with AssetBundle dependencies.

To get a useable AssetBundleManifest object, you'll need to load that additional AssetBundle (the one that's named the same thing as the folder it's in ) and load an object of type AssetBundleManifest from it.

Loading the manifest itself is done exactly the same as any other Asset from an AssetBundle:

 AssetBundle assetBundle = AssetBundle.LoadFromFile(manifestFilePath); AssetBundleManifest manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

Though it is not well documented to be honest, in the examples around AssetBundles.LoadFromFile you can see that they do not load the "Example.manifest" as AssetBundle but rather only "Example" without a suffix!

So in your case it seems to be placed in Assets/uia and you would load this archive as AssetBundle, not a specific file in it.

AssetBundle assetBundle =  AssetBundle.LoadFromFile(Path.Combine(Application.dataPath, "uia"));
AssetBundleManifest manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

Also see the AssetBundle Manual

“AssetBundle” can refer to two different, but related things.

First is the actual file on disk. This is called the AssetBundle archive. The AssetBundle archive is a container, like a folder, that holds additional files inside it .

→ the manifest is a part of this archive and can only be loaded by loading the AssetBundle and then grab the manifest from it!

The file you have to load in AssetBundle.LoadFromFile is the file Assets , which is a file that is stored in the same folder as your AssetBundle uia . This Assets file gets the same name as the folder is stored in, in this case Assets . Your code would be like this:

AssetBundle ab = AssetBundle.LoadFromFile(Application.dataPath + "/Assets");
AssetBundleManifest manifest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM