1. Packing
Right click on the left side of this interface, CreateNewBundle
Make the model to be packaged into a preset body
Check below
Select the platform path and click Build
2. Load AB package
public class ABTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//加载AB包
AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "model");
//加载AB包资源
//用这个重载,因为Lua不支持泛型
GameObject obj = ab.LoadAsset("Cube",typeof(GameObject)) as GameObject;
Instantiate(obj);
obj = ab.LoadAsset("Sphere", typeof(GameObject)) as GameObject;
Instantiate(obj);
}
// Update is called once per frame
void Update()
{
}
}
3. Uninstall resources
ab.Unload(bool a) function
Filling in the parameter true will unload already loaded and used resources, and false will only unload the loaded resources.