AssetBundle资源打包中的依赖问题

AssetBundle资源打包中的依赖问题

  关于的AB打包详细问题请查看我这篇博客Unity中的AssetBundle资源打包和加载以及从本地服务器进行加载
AssetBundle资源打包中的依赖问题_第1张图片
  如图,我将Snipaste_2019-04-15_15-34-11这个材质球的AB标签设为了mater进行打包,cube上有它的材质依赖。
如果此时直接按以下代码进行ab加载,会出现材质丢失:

void Start()
    {
        //当有依赖关系时,需要加载依赖,才不会造成资源的依赖丢失
        //string abMaterPath = Application.dataPath + "/AssetBundleTest/AssetBundles/mater";
        //依赖的加载
        //AssetBundle abMater = AssetBundle.LoadFromFile(abMaterPath);

        //ab文件中的car的文件路径
        string abCubePath = Application.dataPath + "/AssetBundleTest/AssetBundles/cube";
        //加载ab文件
        AssetBundle abCube = AssetBundle.LoadFromFile(abCubePath);
        //压缩文件进行解压
        GameObject cube = abCube.LoadAsset<GameObject>("Cube");
        //复制
        GameObject cube1 = Instantiate(cube);
    }

  运行unity如图:
AssetBundle资源打包中的依赖问题_第2张图片
  如果将代码中依赖加载的代码取消注释,则不会出现依赖丢失的问题了。
AssetBundle资源打包中的依赖问题_第3张图片

你可能感兴趣的:(Unity)