Welcome to the Bundle Resources documentation page. Bundle Resources is intended to make the process of migrating from using the Resources folder to asset bundles as painless as possible, with minimal project hierarchy changes, and minimal code changes.
After importing the package, navigate to the FSG/BundleResources/Resources/ folder and select the BundleResourcesSettings asset. Here you can see the list of folders that will be bundled as well as other settings.
Once you have decided which assets you would like to move from Resources into Asset Bundles, create (or rename) a folder named ResourcesBundled. Using this folder name will automatically add it to the bundling process. Also, a folder can be dragged into the Bundle Folders array inside of the BundleResourcesSettings asset.
By default, folder structure determines how assets will be bundled. Each folder and sub-folders will be put into it's own bundle. If you would like to use BundleResources.LoadAll
to load all assets in a folder, and it's sub-folders, drag the folder into the Single Bundle Folders array in the BundleResourcesSettings asset.
This asset stores settings about folders to be bundled as well as an asset index for editor use. It can be easily selected by navigating to the Assets > Bundle Resources > Select Bundle Resources Settings.
The Resources Script Replacer is a utility that makes it easier to find and replace Resources.Load
and Resources.LoadAll
calls in the project.
Tool Usage
Resources.Load
calls.Resources
, or replace the it with BundleResources.Load.
Using Bundle Resources is virtually the same as using a Resources folder. If you have not used the Resources before, familiarize yourself with it here. All of the calls remain the same, excluding Resources.UnloadUnusedResources().
Converting The Project
Resources.Load
calls with BundleResources.Load
.BundleResources.LoadAsync
returns a CustomYieldInstruction
not a ResourceRequest
.CustomYieldInstruction
can be yielded on just like a ResourceRequest
, and has the same properties.IEnumerator LoadAsset() { // Load bundle and asset asynchronously var request = BundleResources.LoadAsync<Material>("Materials/MyMaterial"); // Wait for it to finish loading yield return request; // Retrieve the asset Material loadedMaterial = request.asset; // Unload the bundle it was loaded from to free up memory // NOTE passing true into this method also unloads any assets loaded from the bundle BundleResources.UnloadBundle("Materials/MyMaterial", false); }
If you have any questions or issues please email me at jschieck@gmail.com and thanks for your support!
// Loads an Object from an asset bundle // Asset path relative to the parent bundled folder public static Object Load(string path); // Loads an Object of the specified System.Type from an asset bundle // Asset path relative to the parent bundled folder // System.Type of object to load public static Object Load(string path, System.Type systemTypeInstance); // Loads an Object of type T from an asset bundle // Asset path relative to the parent bundled folder public static T Load<T>(string path) where T : Object; // Loads all Object's in the folder // Asset path relative to the parent bundled folder public static Object[] LoadAll(string path); // Loads all Object's in the folder // Asset path relative to the parent bundled folder // System.Type of object to load public static Object[] LoadAll(string path, System.Type systemTypeInstance); // Loads all objects of type T from an asset bundle // Asset path relative to the parent bundled folder public static T[] LoadAll<T>(string path) where T : Object; // Loads an Object from an asset bundle asynchronously // Asset path relative to the parent bundled folder public static BundleResourceRequest<Object> LoadAsync(string path); // Loads an Object of the specified System.Type from an asset bundle asynchronously // Asset path relative to the parent bundled folder // System.Type of object to load public static BundleResourceRequest<Object> LoadAsync(string path, System.Type type); // Loads an Object of type T from an asset bundle asynchronously // Asset path relative to the parent bundled folder public static BundleResourceRequest<T> LoadAsync<T>(string path) where T : Object; // Unloads all loaded asset bundles // Also unload any loaded objects from the bundle public static void UnloadBundles(bool unloadAllLoadedObjects = true); // Unloads the specified bundle for the path provided // Path of the object, or folder, relative to the parent bundled folder public static void UnloadBundle(string path, bool isFolderPath, bool unloadAllLoadedObjects = true);