2024年5月4日发(作者:)
loaded from the server on demand. More on that in .
2. Loading objects from AssetBundles. Once the AssetBundle is downloaded, you might want to access its individual Assets from the
Bundle. More on that in
Please read this section of the documentation thoroughly to familiarize yourself with the workflow for using AssetBundles, discover the
different features they provide and learn best practices that can save you time and effort during development.
See also:
Building AssetBundles
There are three class methods you can use to build AssetBundles:
allows you to build AssetBundles of any type of asset.
is used when you want to include only scenes to be streamed and loaded as the data becomes available.
is the same as ssetBundle but has an extra parameter to specify a custom string identifier (name) for each
object.
An example of how to build an AssetBundle
Building asset bundles is done through editor scripting. There is basic example of this in the scripting documentation for .
BuildAssetBundle
For the sake of this example, copy and paste the script from the link above into a new C# script called ExportAssetBundles. This script
should be placed in a folder named Editor, so that it works inside the Unity Editor.
Now in the Assets menu, you should see two new menu options.
1. Build AssetBundle From Selection - Track dependencies. This will build the current object into an asset bundle and include all of its
dependencies. For example if you have a prefab that consists of several hierarchical layers then it will recursively add all the child
objects and components to the asset bundle.
2. Build AssetBundle From Selection - No dependency tracking. This is the opposite of the previous method and will only include the
single asset you have selected.
For this example, you should create a new prefab. First create a new Cube by going to GameObject -> Create Other -> Cube, which will
create a new cube in the Hierarchy View. Then drag the Cube from the Hierarchy View into the Project View, which will create a prefab of
that object.
You should then right click the Cube prefab in the project window and select Build AssetBundle From Selection - Track dependencies. At
this point you will be presented with a window to save the "bundled" asset. If you created a new folder called "AssetBundles" and saved
the cube as 3d, your project window will now look something like this.
At this point you can move the AssetBundle 3d elsewhere on your local storage, or upload it to a server of your choice.
An example of how to change the properties of the assets when building an Asset
Bundle
发布评论