Creating Assets - theLeaxx/JaLoader GitHub Wiki
Introduction
Assets (asset bundles) allow you to use prefabs made in Unity in your mods.
Required Unity Version
Before you begin creating asset bundles, ensure that you are using Unity version 2017.4.23f1. You can find it here.
Building asset bundles
If you've never used Unity before, I suggest you look up its official documentation or watch a few beginner videos about it - you're not going to need to know much
To create AssetBundles in Unity, you can use the following script. This script is an example of how to build asset bundles in the Unity:
using UnityEditor;
using System.IO;
using System;
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
if(!Directory.Exists("AssetBundles")
Directory.CreateDirectory("AssetBundles");
BuildPipeline.BuildAssetBundles("AssetBundles", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
}
This script defines a menu item, "Build AssetBundles," accessible from Unity. When selected, it triggers the BuildAllAssetBundles method, which builds asset bundles and saves them in the "AssetBundles" directory.
Using the script
- Open Unity
- Create a folder named
Scripts, and inside it another one namedEditor. In theEditorfolder, create a new script namedCreateAssetBundles - Open it, and paste in the code from above, then save.
- Back in Unity, if you right-click in the project explorer window, you should now see an option called
Build AssetBundles - Click on "Build AssetBundles" to execute the script, which will create asset bundles in the "AssetBundles" directory
- If you have trouble finding the
AssetBundlesdirectory, right-click in the project explorer window, and click onShow in Explorer- going back a folder, you should now see theAssetBundlesdirectory
How do I specify which assets I'd like to build?
If you'd like to use objects, you need to make prefabs of them, and then continue following this guide. To specify which assets you want to include in the asset bundle, follow these steps:
- Navigate to the asset you want to include in the bundle in the Project Explorer window
- Click on it, to select it
- In the Inspector window, locate the "AssetBundle" field. It's usually in the bottom-right portion, and looks like this:
- Click on
None, then onNew..., and name it anything you'd like. You can add multiple assets into a single bundle, and then load them like this.