Unity 3-7 Assetbundle from getting started to mastering Tasks 1&2&3: Course Introduction
Assetbundle--Update for resources
Lay the groundwork for later Xlua (the LUA hot-updated framework)
Definition and function of task 4&5:assetbundle
Assetbundle Learning--a Learning Resource: unitymanual, Assetbundles, tutorial-style documentation
Assetbundle is a compressed package (which can also be considered a folder)
Includes model, map texture, preform prefab, sound audioclip, and even entire scene
Can be loaded when the game is running
This package is packaged out on a hard disk and contains files that can be divided into two categories: serialized file and resource files
Serialized file: A resource, such as a model, a prefab, is broken and placed in an object, and the final unification is written into a separate file
Resource file: Some binary resources, slices, sounds, are saved separately for quick loading
--a single picture or sound will be packaged into a. resource file
Compression packs can use the LZMA and LZ4 compression algorithms to facilitate faster network transmission--the difference will tell
Why do you use network transmission?
1. Put some downloadable resources in the Assetbundle, not in the app, and load the resources directly from the Internet when needed
-- reduce the size of the installation package
The installation package is too large: affects the user experience, or causes users not to download
2. Easy to update
-- for some models, if some active updates are made , the user does not need to update the installation package
After entering the game, check the resource update, download the model from the server and load it
After the first boot, or after an update, download the update package locally, and then do not download the
The assetbundle themselves preserve the interdependence of each other.
For example, a package is dedicated to saving the model, and the other package is dedicated to save the map, the two packages will have a dependency between the
Assetbundle when loading, as a Assetbundle object, the content contained in the object is the contents of the Assetbundle compressed package
Task 6:assetbundle Use Process
Https://docs.unity3d.com/Manual/AssetBundles-Workflow.html
1. Specifying the Assetbundle property of a resource
2. Build Assetbundle Package
Assetbundle package can have multiple, each Assetbundle package can have multiple files
Unity will search for resources in the project, and if the resource is flagged and needs to be packaged, it will be packaged in the Assetbundle package
3. Upload Assetbundle Package
In general, it is uploaded to the server
4. Load the Assetbundle package and the resources in it
After you start the game, the game checks for updates on the server, downloads the update package locally, loads the resources above
Task 7&8: Pack Assetbundle
1. Specifying the Assetbundle property of a resource
Search for material resources from Assetstore
Create a cube, stretch it into a wall shape, attach the mat resource to the
Made into a prefab named wall.
Modify the Assetbundle label for Wall Prefab, New-Wall (case-insensitive)
It can also be written in AAA/BBB format, indicating that a assetbundle file named BBB is generated under the AAA folder
For example: Scene/wall
Suffix written assetbundle, not necessary, random fill in the line
Different items that are set to the same Assetbundle property are packaged in the same Assetbundle file
2. Build Assetbundle Packages using Unity's API
This API is only run in editor mode.
Create Editor folder
New CreateAssetBundles.cs Script
Using Unityeditor;
Do not inherit from Monobehaviour
Buildpipeline.buildassetbundles (String outputPath, buildassetbundleoptions option, Buildtarget platform);
string path; Path is based on the root of the project-the output directory needs to exist, and unity does not automatically create the path
So there is a need to determine if the path exists.
Using System.IO;
if (! Directory.Exists (path)) {
directory.createdirectory (path);
}
buildassetbundleoptions. None//means not to set this option
Buildtarget. STANDALONEWINDOWS64//Indicates the package for WINDOW64 platform
using unityeditor; using System.IO; Public classcreateassetbundle { [MenuItem ( "assets/buildassetbundles")] Static voidBuildallassetbundles () {stringPath ="Assetbundles"; if(! directory.exists(path)) { directory.createdirectory(path); } buildpipeline.buildassetbundles(path, buildassetbundleoptions. None, buildtarget. STANDALONEWINDOWS64);}}
[MenuItem ("Assets/buildassetbundles")]//means this method creates a submenu under the menu bar Assets buildassetbundles
Unity, Assets-click Buildassetbundles, will be assetbundle packaging
There are no changes under project in Unity,
Open the project root directory in the system and you will find a new Assetbundles folder
Wall.assetbundle is Wall's prefab file.
Wall.assetbundle.manifest records the dependencies of Wall.assetbundle
Assetbundles is for the current directory
Assetbundles.manifest which assetbundle files are generated by the current directory
. manifest is a text file, and a Assetbundle file corresponds to a manifest file
Records the corresponding Assetbundle dependencies, see Task 14
How do I delete a assetbundle name ?
For example, now find our assetbundle name is wrong, regenerate a assetbundle
However, setting the Assetbundle property in the menu will find that the original Assetbundle name is not replaced, still exists
Where you set the Assetbundle property of the resource, select Remove unused names
Now, you can't find the unused Assetbundle name in the menu that sets the Assetbundle property.
Load and use of task 9:assetbundle
3. Upload Assetbundle Package
Because in the development phase, we want to repeat the Assetbundle package, so we do not upload to the server this operation
The development phase directly places the Assetbundle package locally and then loads
4. Load Assetbundle Package
Here, we'll start by loading the local Assetbundle package.
The APIs used to load the local Assetbundle package and load the Assetbundle package on the server are different
Now, empty the items in our scene and the Prefab in project
In order to see more clearly that the object is loaded from the Assetbundle
Create an empty object, name Loadassetbundle
Add Script LoadAssetBundleFromLocal.cs
Load operation in Start ()
Assetbundle.loadfromfile ("Assetbundles/scene/wall.assetbundle");
Need to add suffix
The return value is an object of type Assetbundle-see task 4&5:
Assetbundle when loading, as a Assetbundle object, the content contained in the object is the contents of the Assetbundle compressed package
Assetbundle Assetbundle = ...;
Gameobject Wallprefab = assetbundle.loadasset<GameObject> ("Wall");
Object type Gameobject, named "Wall", assigns the loaded resource to the Gameobject object
Here the name "Wall" can not be written, need and packaging before the same name--case-insensitive
Instantiate (Wallprefab);
Another method is assetbundle.loadallassets ();
Returned is object[],
You can instantiate all the prefabs that are contained in all object[] by using foreach
Siki_unity_3-7_assetbundle from getting started to mastering