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.
Next, follow the process of building the AssetBundle according to the document.
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:
Then the corresponding folder will appear in the project
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.
The result is that errors are reported and cannot be found.
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.
The actual path in my project
Then start the loading operation.
It is still an official example. Mine is a picture and is loaded using the picture name.
Then it loaded successfully~~
At this time, I tried deleting the original image and it still loaded normally.
Go here to load the Asset Bundle locally and debug it.
Try the network loading method later.
March 01, 2023 14:09:28