1、什么是依赖关系
有时候一个模型所需要的东西可能在不同的包里面,例如蓝色立方体的模型和材质在不同的包(mode和head)里,这时需要加载两个包才能让这个球正常显示
2、如何获取依赖关系并加载
//加载AB包
AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "model");
//AssetBundle ab2 = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "head");
//获取依赖关系
//加载主包
AssetBundle abMain = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "PC");
//加载主包中的固定文件(固定写法)
AssetBundleManifest abMainfest = abMain.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
//得到依赖信息(例如这个model)
string[] strs = abMainfest.GetAllDependencies("model");
//用得到的字符串去加载相应的包
for (int i = 0; i < strs.Length; i++)
{
print(strs[i]);
AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + strs[i]);
}
//ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "head");
//加载AB包资源
//用这个重载,因为Lua不支持泛型
GameObject obj = ab.LoadAsset("Cube",typeof(GameObject)) as GameObject;
Instantiate(obj);
GameObject obj2 = ab.LoadAsset("Sphere", typeof(GameObject)) as GameObject;
Instantiate(obj2,new Vector3(1,1,1),Quaternion.identity);
运行结果