Unity Asset Bundle Learning-Loading local resources

Unity’s Asset Bundle documentation
https://docs.unity3d.com/cn/2019.4/Manual/AssetBundles-Workflow.html

For the first contact, follow the official documentation directly.

Insert image description here
Insert image description here

Next, follow the process of building the AssetBundle according to the document.
Insert image description here


This script will create a menu item called Build AssetBundles at the bottom of the Assets menu , which will execute the code in the function associated with that tag. When you click Build AssetBundles
, a progress bar will appear along with the build dialog. This process will take all assets tagged with the AssetBundle name and place them in
a folder in the path defined by assetBundleDirectory.

Execution result:
Insert image description here

Then the corresponding folder will appear in the project
Insert image description here

Then load according to the sample loading method.
I encountered a problem here.
The code is like this. I directly copied the sample code and changed the name of the load. Because I didn’t know which one to use for the file structure I generated, I tried them all.
Insert image description here

The result is that errors are reported and cannot be found.
Insert image description here

So I checked the details of the AssetBundle.LoadFromFile method.
Official document: https://docs.unity.cn/cn/2019.4/ScriptReference/AssetBundle.LoadFromFile.html
. I found out that it was the Path.Combine method and I didn’t understand it, so I continued. See the
official document: https://docs.unity.cn/cn/2019.4/ScriptReference/Path.Combine.html
I found that it was just a splicing method,
so I changed the method and printed out the splicing address.

Finally, I found that there was a problem with the path and I couldn’t use it according to the example. I
changed it and it became normal.
Insert image description here

The actual path in my project
Insert image description here

Then start the loading operation.
It is still an official example. Mine is a picture and is loaded using the picture name.
Insert image description here

Then it loaded successfully~~
At this time, I tried deleting the original image and it still loaded normally.
Insert image description here

Go here to load the Asset Bundle locally and debug it.
Try the network loading method later.
March 01, 2023 14:09:28

Guess you like

Origin blog.csdn.net/qq_32065601/article/details/129280013