1.ab包的打包
使用AssetBundles-Browser-master 工具进行打包。
注意:下载到项目后需要把包的Texts文件夹删除,不然会报错
2.ab包的加载
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
public class SimpleLoad:MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//加载AB包
AssetBundle ab = AssetBundle.LoadFromFile("ab包的路径");
ab.LoadAsset<"该AB包的资源类型">("该AB包内的资源名称");
StartCoroutine(LoadGameobject());
}
//异步加载Resources里的资源
IEnumerator LoadGameobject()
{
ResourceRequest rr = Resources.LoadAsync<GameObject>("Cube");
yield return rr;
Instantiate<GameObject>(rr.asset as GameObject);
}
//异步加载AB包
IEnumerator LoadABobject()
{
AssetBundleCreateRequest abcr = AssetBundle.LoadFromFileAsync("AB包的文件路径");
yield return abcr;
abcr.assetBundle.LoadAsset<资源类型>("资源名");
}
}