Quickstart
Simulation mode
First of all, you don't need to build your bundles to actually use this plugin. If you enable the Simulation mode from the Wonderland/AssetBundles/Simulation Mode
menu, the plugin will load your assets using their bundles metadata.
Standard Manager (turnkey solution)
Take a look at ABStandardManager.
Initialization
Before using any function in AssetBundles, you have to initialize it successfully with a source location from which it will download the bundles if it does not find them in the cache. Make sure to always use a try/catch to handle errors properly since every async operation can throw due to network / io / arguments errors.
async void Start() {
try {
await AssetBundles.Init("path/to/bundles/root");
} catch (Exception e) {
// Handle exception (network error / io error etc..) maybe by showing an error popup to the user.
Debug.LogError("AssetBundles init error: " + e);
}
}
The bundles root url or path is the location where all platform bundles live (Windows/Android/iOS/etc...) and not the platform bundle directly. The plugin handles the platform detection internally and automatically appends the platform name after your path to target the right platform folder.
- Assets
- StreamingAssets
- Bundles (This is your bundles SourceURL)
- Windows (Folder for Windows bundles)
- Android (Folder for Android bundles)
- iOS (Folder for iOS bundles)
- etc...
- Bundles (This is your bundles SourceURL)
- StreamingAssets
If your folder structure looked like the one above, you would pass Path.Combine(Application.streamingAssetsPath, Bundles)
to the Init function.
To learn more about the initialization step, check out Initialization.
Loading assets
Loading one or mulitple assets is quite similar.
To load a single asset, you need to know its bundle, name and type.
try {
var prefab = await AssetBundles.LoadAsset<GameObject>("wonderland-tests", "Cube");
} catch(Exception e) {
// Something wrong happened
}
Using the same logic, you can load multiple assets in a bundle without knowing their names.
try {
var allPrefabs = await AssetBundles.LoadAllAssets<GameObject>("wonderland-tests");
} catch(Exception e) {
// Something wrong happened
}
To ease the loading of single assets, we provide the BundledAsset
struct which is a simple wrapper around two strings, bundle and asset names. The struct is Serializable and can be exposed in the inspector.
To learn more about the assets loading step, check out Loading.
Going deeper
Now that you know the basics, you can read more about the specific steps in the Steps section and look at concrete examples in the Examples section.