LoadAssets methods - piotrulos/MSCModLoader GitHub Wiki
LoadAssets.LoadBundle()
There are 3 ways of loading asset bundle
- From mods
Assets
folder as file - From Embedded Resources.
- From Resources (.resx properties) inside .dll
It is NOT recommended to bundle assets that are big, like above 40 MB in total. Embedded assets (or Resources) can take double time to load and double the memory usage.
Overloads
AssetBundle LoadBundle(Mod mod, string bundleName);
AssetBundle LoadBundle(byte[] assetBundleFromResources);
AssetBundle LoadBundle(string assetBundleEmbeddedResources);
Load From Assets Folder
Easiest way to load assetbundle
void OnLoad()
{
AssetBundle ab = LoadAssets.LoadBundle(this, "myAssets.unity3d");
//Do whatever needed with assetbundle.
ab.Unload(false);
}
This will load myAssets.unity3d
from Assets
folder.
myAssets.unity3d
should be in: \Mods\Assets\YourModId\myAssets.unity3d
Load From Embedded Resources
Embedded Resources are easier than regular Resources.
void OnLoad()
{
AssetBundle ab = LoadAssets.LoadBundle("MyMod1.Assets.myBundle.unity3d");
//Do whatever needed with assetbundle.
ab.Unload(false);
}
Add your bundle just by creating new folder in solution explorer and adding your file there, and set Build Action
to embedded resources
Name of the bundle is in most cases Namespame.FolderName.filename.extension
on this example it is "MyMod1.Assets.myBundle.unity3d"
Load From Resources (.resx)
Creating resources is a bit more complex
void OnLoad()
{
AssetBundle ab = LoadAssets.LoadBundle(Properties.Resources.myBundle)
//Do whatever needed with assetbundle.
ab.Unload(false);
}
Go to properties of your mod and click resources
Create resource file as prompted.
Click Add resource
and Add existing file
and select your bundle
To find full name you need to usually open resources file to find Properties.Resources.myBundle