Ejemplo n.º 1
0
    /**
     * 通过assetbundle名字取到assetbundle
     * 异步加载assetbundle
     * */
    public void GetAssetBundleAsyn(string name, LoadCallBack <AssetBundle> callBack)
    {
        string      abPath = this.GetAbsolutePath(name);
        AssetBundle bundle = null;

        if (abLoadDic.TryGetValue(abPath, out bundle))
        {
            if (callBack != null)
            {
                callBack(bundle);
            }
            return;
        }
        LoadCallBack <AssetBundle> addMapCallBack =
            (assetBundle => { abLoadDic.Add(abPath, assetBundle); if (callBack != null)
                              {
                                  callBack(assetBundle);
                              }
             });

        SingleAssetBundleLoader loaderData = new SingleAssetBundleLoader(name, abPath, addMapCallBack);

        string[] dependencies = mainfest.GetAllDependencies(name);
        int      number       = 0;

        LoadCallBack <AssetBundle> loadEndCallback =
            (assetbundle => { number += 1; if (number == dependencies.Length)
                              {
                                  loaderData.Load();
                              }
             });

        if (dependencies.Length > 0)
        {
            foreach (string dependency in dependencies)
            {
                GetAssetBundleAsyn(dependency, loadEndCallback);
            }
        }
        else
        {
            loaderData.Load();
        }
    }
        private string _simpleAssetName = "Cylinder.prefab";       // 需要加载的资源名称

        private void Start()
        {
            _assetBundleLoader = new SingleAssetBundleLoader(_abName, LoadComplete); // 创建实例
            StartCoroutine(_assetBundleLoader.LoadABWWW());                          // 加载Ab包
        }