Unity的AB包相关

1、打包

在这个界面左边右键,CreateNewBundle

将要打包的模型制作成预设体

在下面勾选

选好平台路径,点击Build

2、加载AB包

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、卸载资源

ab.Unload(bool a)函数

参数填true会把已经加载使用也卸载了,false只卸载加载的资源。

猜你喜欢

转载自blog.csdn.net/holens01/article/details/133200283
今日推荐