Assets

These APIs allow you to load assets (usually asset bundles) or binary files from your mod.

To create and add assets to your mod, please see Working With Assets

Assets.LoadBundle

Assets.LoadBundle(string bundleName, string optionalModUuid = null)

Load a bundle with the given filename (including extension) from your mod.

The path is relative to the root of your source files and the file must be included in your solution as per Working With Assets

An optional optionalModUuid can be specified to try to load a bundle / asset from another mod.

When the bundle is loaded, the OnBundleLoaded(string bundleName, object bundle) method on your Mod's MonoBehaviour will be called by the SDK.

An example of handling asset loading is as follows:

Assets.LoadBundle("azzamaster");

This chunk starts the async loading process of the bundle.

void OnBundleLoaded(string bundleName, object bundle)
{
    // Cast to an asset bundle
    AssetBundle thisBundle = (AssetBundle)bundle;

    // Check which asset bundle was loaded
    if (bundleName == "newselection")
    {
        Object prefabNewSelection = thisBundle.LoadAsset("AzzaFishSelection");

        // Consider checking if all assets are loaded, or doing something with the asset
    }
}

This chunk will be called when the bundle is loaded, it tries to pull out the AzzaFishSelection asset within the asset bundle that was loaded.

Assets.LoadData

Assets.LoadData(string dataName, string optionalModUuid = null)

Load a binary file with the given filename (including extension) from your mod.

The path is relative to the root of your source files and the file must be included in your solution as per Working With Assets

An optional optionalModUuid can be specified to try to load a binary file from another mod.

An example is as follows:

Assets.LoadData("somefile.txt");

This chunk starts the async loading process of the binary file.

void OnDataLoaded(string fileName, byte[] loadedData)
{
    // Check which asset bundle was loaded
    if (fileName == "somefile.txt")
    {
        // Do something with the loadedData
        Log.info("Loaded a binary file with the contents: " + System.Text.Encoding.UTF8.GetString(loadedData));
    }
}

This chunk will be called when the binary file is successfully loaded. You get the raw file contents of the asset as a byte array.