Demo for AssetBundle 5.0 to demonstrate what we can do in the new AssetBundle system. Please base on Unity 5.0 beta 21 or above to run this demo.
There're 3 scenes under TestScenes folder:
- AssetLoader.unity demonstrates how to load a normal asset from AssetBundle, please refer to LoadAssets.cs script.
- SceneLoader.unity demonstrates how to load a scene from AssetBundle, please refer to LoadScenes.cs script.
- VariantLoader.unity demonstrates how to load variant AssetBundle, please refer to LoadVariants.cs script.
We use AssetBundle variants to achieve the same result as virtual assets. In the demo, we build
Please make sure the assets exactly match in these folders. The objects in these two variant AssetBundles will have the exactly same internal IDs which is ensured by Unity build pipeline, so they can be switched out arbitrarily with AssetBundles of different variant extensions. Here the file extension "hd" and "sd" are what we call variants. You can change the active variant which is on LoadVariants.cs. Please also refer to AssetBundleManager.RemapVariantName() to see how to resolve the correct AssetBundle according to the active variant. Reminder: AssetBundle variant is not compatible with the Editor simulation.
1. "My Assets HD" folder into "variant/myassets.hd" AssetBundle. 2. "My Assets SD" folder into "variant/myassets.sd" AssetBundle. 3. "variant-scene.unity" into "variants/variant-scene.unity3d" AssetBundle which actually depends on variant AssetBundle.
Download dependent AssetBundles automatically In the new build system, the dependencies between AssetBundles are tracked in the single manifest AssetBundle. So you can get all the dependencies at runtime, and download all the dependencies automatically with a base url. Please check AssetBundleManager.LoadDependencies() in the demo for more details.
There're 3 menu items under the AssetBundles menu:
- "Simulate AssetBundles" which is used to control AssetBundle simulation in the Editor. In Editor play mode, you can simulate the AssetBundles without actually building them.
- "Build AssetBundles" which simply calls BuildPipeline.BuildAssetBundles() to build the AssetBundles which are set from the AssetBundle UI, check BuildScript.BuildAssetBundles() for details.
- "Build Player" which copies the AssetBundles to StreamingAssets folder then build the player data according to the build settings, check BuildScript.BuildPlayer() for details.
AssetBundleManager class which takes of loading AssetBundle and its dependencies, it contains:
- Initialize() Initialize the AssetBundle manifest object.
- LoadAssetAsync() Load a given asset from a given AssetBundle and handle all the dependencies.
- LoadLevelAsync() Load a given scene from a given AssetBundle and handle all the dependencies.
- LoadDependencies() Load all the dependent AssetBundles for a given AssetBundle.
- BaseDownloadingURL Set the base downloading url which is used for dependencies automatic downloading.
- SimulateAssetBundleInEditor Set if simulating AssetBundle in Editor play mode.
- Variants Set the active variant.
- RemapVariantName() Resolve the correct AssetBundle according to the active variant.
The scripts under Assets\ScriptsForAssetBundleSystem folder could be useful for your project. Please feel free to copy/integrate into your own projects.