2. Loading management module (Loader) - supports free switching of three modes: Resources, Editor, Assetbundle
- JLGames.RocketDriver.Actions.Loader provides full support for the loader.
- “Tools -> RocketDriver -> Project -> Gen LoaderSettings” provides the generation entry for the loader configuration file.
2.1 Initialization
2.1.1 Generate configuration assets
Execute menu “Tools -> RocketDriver -> Project -> Gen LoaderSettings”.
The LoaderSettings.asset (renameable) file will be generated under the project Assets/Resources.
2.1.2 Set configuration according to project requirements
There are 5 available configurations in LoaderSettings, one Editor mode, two Resource modes, and two AssetBundle modes.
2.1.3 Initializing Loaders with Configuration
Initialize the loader with the following API:
- Initialize with the configuration file name generated by first point.
- Initialize with a configuration instance.
- There is a shortcut initialization function in the Loader static class:
Call the function in the loader instance:
- The function callback is executed after the initialization version ends, and the initialization result can be judged internally: success or failure.
- The function requires to open the coroutine call, you can use LoaderManager.Mono to open the coroutine:
2.2 Use
2.2.1 Load Bundle assets
Bundle assets can be loaded only after the Bundle version information is initialized.
The loader implements the IBundleLoader interface and contains functions related to loading Bundle assets.
Loading Bundle assets requires the use of coroutines, which can be enabled using a LoaderManager.Mono instance to load Bundles by coroutines.
- bundleName: bundle asset name.
- onBundleLoaded: Execute the result callback, which can be used to determine whether it is successful or not.
- autoRelease: Indicates whether to release the bundle instance after onBundleLoaded execution ends
- unloadAllLoadedObjects: Indicates whether to release the resource assets instantiated from the bundle instance after onBundleLoaded execution ends
- If autoRelease is true, all assets to be used should be instantiated in onoBundleLoaded.
2.2.2 Loading resource assets
In the case of obtaining the bundle instance, the instance of the resource asset can be instantiated from the bundle instance, and then cloned and used.
It is recommended to use synchronous functions for loading resource assets, and asynchronous functions are not recommended. The reason is that Unity does not support opening coroutines within coroutines friendly, and if there are too many layers (like 16 layers), unpredictable errors will appear.
The IAssetLoader interface functions are divided into four categories:
- Single resource asset loading (sync|async)
- Batch resource asset loading (sync|async)
- Single sub-resource asset loading (sync|async)
- Batch sub-resource asset loading (sync|async)
- For more usage, please refer to the example, API or source code.
2.3 Example
JLGames/RocketDriver/Samples/Loader