Example #1
0
 /// <summary>
 /// 卸载 bundle
 /// </summary>
 /// <param name="loader"></param>
 /// <param name="unloadAllObjects"></param>
 public void UnLoadAssetBundle(AssetBundleLoader loader, bool unloadAllObjects = false)
 {
     UnLoadAssetBundle(loader.abName, unloadAllObjects);
 }
Example #2
0
        IEnumerator AsyncLoadAssetBundle(AssetBundleLoader loader)
        {
            AssetBundleInfo          bundleInfo = null;
            List <AssetBundleLoader> loaderList = null;

            // 查询所有依赖,先加载依赖资源
            string[] dependencies = mainManifest.GetAllDependencies(loader.abName);
            for (int i = 0; i < dependencies.Length; i++)
            {
                var dName = dependencies[i];
                bundleInfo = GetBundleDic(dName);

                if (bundleInfo == null)
                {
                    loaderList = GetLoadDic(dName);

                    if (loaderList == null)
                    {
                        // 添加到正在加.载字典
                        AddLoadDic(dName, loader);

                        AssetBundleCreateRequest dRequest = AssetBundle.LoadFromFileAsync(GetAssetBundlePath(dName));
                        yield return(dRequest);

                        // 加载完成添加到缓存
                        bundleInfo = new AssetBundleInfo(dRequest.assetBundle);
                        bundleInfo.referencedCount = GetLoadCount(dName);
                        AddBundleDic(dName, bundleInfo);

                        // 移出loadDic
                        RemoveLoadDic(dName);
                    }
                    else
                    {
                        AddLoadDic(dName, loader);
                    }
                }
                else
                {
                    bundleInfo.referencedCount++;
                }
            }

            // 加载资源
            bundleInfo = GetBundleDic(loader.abName);
            if (bundleInfo == null)
            {
                loaderList = GetLoadDic(loader.abName);

                if (loaderList == null)
                {
                    // 添加到正在加载字典
                    AddLoadDic(loader.abName, loader);

                    AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(GetAssetBundlePath(loader.abName));
                    yield return(request);

                    // 加载完成添加到缓存
                    bundleInfo = new AssetBundleInfo(request.assetBundle);
                    AddBundleDic(loader.abName, bundleInfo);

                    // 回调加载
                    loaderList = GetLoadDic(loader.abName);
                    for (int i = 0; i < loaderList.Count; i++)
                    {
                        loaderList[i].CallCompleted(bundleInfo.assetBundle);
                    }

                    // 移出loadDic
                    RemoveLoadDic(loader.abName);
                }
                else
                {
                    AddLoadDic(loader.abName, loader);
                }
            }
            else
            {
                bundleInfo.referencedCount++;

                // 回调加载
                loader.CallCompleted(bundleInfo.assetBundle);
            }
        }