예제 #1
0
        /// <summary>
        /// 释放一个场景里面所有资源
        /// </summary>
        /// <param name="sceneName">Scene name.</param>
        public void Dispose(string sceneName)
        {
            List <string> disposeAb = new List <string>();

            foreach (string key in dicAbCach.Keys)
            {
                string tempSceneName = dicAbCach[key].AbParam.SceneName;
                if (tempSceneName.Equals(sceneName))
                {
                    dicAbCach[key].AbState = EnumAbState.Release;
                    disposeAb.Add(key);
                }
            }

            if (dicAllScenes.ContainsKey(sceneName))
            {
                MultiABMgr multiABMgrObj = dicAllScenes[sceneName];
                multiABMgrObj.DisposeAllAsset();
                dicAllScenes.Remove(sceneName);
            }

            else
            {
                Debug.LogWarning(GetType() + "/DisposeAllAssets()/找不到场景名,释放资源失败! sceneName=" + sceneName);
            }

            for (int i = 0; i < disposeAb.Count; i++)
            {
                dicAbCach.Remove(disposeAb[i]);
            }
        }
예제 #2
0
        /// <summary>加载Manifest</summary>
        public void LoadAssetBunlde(string sceneName, string abName)
        {
            if (m_Manifest == null)
            {
                return;
            }
            MultiABMgr tmpMultiABMgr = GetMultiABMgr(sceneName, abName);

            tmpMultiABMgr.LoadAssetBunlde(abName);
        }
예제 #3
0
        /// <summary>
        /// 获取多个Ab资源包
        /// </summary>
        /// <param name="sceneName">场景名称(资源分组)</param>
        /// <param name="abName">资源名称(带后缀名)</param>
        /// <returns></returns>
        private MultiABMgr GetMultiABMgr(string sceneName, string abName)
        {
            abName = abName.ToLower();//将名字转换成小写

            if (!dicAllScenes.ContainsKey(sceneName))
            {
                MultiABMgr multiABMgrObj = new MultiABMgr(abName);
                dicAllScenes.Add(sceneName, multiABMgrObj);
            }

            return(dicAllScenes[sceneName]);
        }
예제 #4
0
        /// <summary>
        /// 获取Ab包中所有资源名称
        /// </summary>
        /// <param name="sceneName">场景名称(资源分组)</param>
        /// <param name="abName">AssetBundle名称(带后缀名)</param>
        /// <returns></returns>
        public string[] RetriveAllAssetName(string sceneName, string abName)
        {
            abName = abName.ToLower();

            if (dicAllScenes.ContainsKey(sceneName))
            {
                MultiABMgr multiABMgrObj = dicAllScenes[sceneName];
                return(multiABMgrObj.RetriveAllAssetName(abName));
            }

            return(null);
        }
예제 #5
0
        /// <summary>
        /// 释放一个场景里面所有资源
        /// </summary>
        /// <param name="sceneName">场景名称(资源分组)</param>
        public void Dispose(string sceneName)
        {
            List <string> disposeAb = new List <string>();

            if (dicAllScenes.ContainsKey(sceneName))
            {
                MultiABMgr multiABMgrObj = dicAllScenes[sceneName];
                multiABMgrObj.DisposeAllAsset();
                dicAllScenes.Remove(sceneName);
            }
            else
            {
                Debug.LogWarning(GetType() + "/DisposeAllAssets()/找不到场景名,释放资源失败! sceneName=" + sceneName);
            }
        }
예제 #6
0
        /// <summary>
        /// 加载Ab包中资源
        /// </summary>
        /// <param name="sceneName">场景名称(资源分组)</param>
        /// <param name="abName">AssetBundle名称(带后缀名)</param>
        /// <param name="assetName">资源名称(带后缀名)</param>
        /// <returns></returns>
        public UnityEngine.Object LoadAsset(string sceneName, string abName, string assetName)
        {
            //将名字转换成小写
            abName = abName.ToLower();

            if (dicAllScenes.ContainsKey(sceneName))
            {
                MultiABMgr multiABMgrObj = dicAllScenes[sceneName];
                return(multiABMgrObj.LoadAsset(abName, assetName));
            }

            Debug.LogWarning(GetType() + "/LoadAsset()/找不到场景名称,无法加载(AB包)中资源! sceneName=" + sceneName);

            return(null);
        }
예제 #7
0
        private IEnumerator loadAssetBunldeAsyn(string sceneName, string abName, Action finish)
        {
            if (m_Manifest == null)
            {
                yield break;
            }

            MultiABMgr tmpMultiABMgr = GetMultiABMgr(sceneName, abName);

            yield return(tmpMultiABMgr.LoadAssetBunldeAsyn(abName));

            if (finish != null)
            {
                finish();
            }
        }
예제 #8
0
        private IEnumerator LoadAssetBundlePackAsyn(string sceneName, string abName, DelLoadComplete loadAllCompleteHandle)
        {
            AbInfo abInfo = null;

            //等待Manifest文件加载完成
            while (!ABManifestLoader.Instance.IsLoadFinish)
            {
                yield return(null);
            }
            manifestObj = ABManifestLoader.Instance.GetABManifest();
            if (manifestObj == null)
            {
                Debug.LogError(GetType() + "/LoadAssetBundlePack()/manifestObj is Null!");
                yield break;
            }

            abName = abName.ToLower();//将名字转换成小写

            if (dicAbCach.ContainsKey(abName))
            {
                dicAbCach.TryGetValue(abName, out abInfo);

                if (abInfo.AbState == EnumAbState.Release)
                {
                    Debug.Log("资源正在释放!abName:" + abName);
                    yield break;
                }

                while (abInfo.AbState == EnumAbState.Loading)
                {
                    yield return(null);
                }

                loadAllCompleteHandle(abName);
                yield break;
            }
            else
            {
                abInfo = new AbInfo();
                AbParam abParam = new AbParam();
                abParam.SceneName = sceneName;
                abParam.AbName    = abName;

                abInfo.AbParam = abParam;
                abInfo.AbState = EnumAbState.Loading;

                dicAbCach.Add(abName, abInfo);
            }

            if (!dicAllScenes.ContainsKey(sceneName))
            {
                MultiABMgr multiABMgrObj = new MultiABMgr(sceneName, abName, loadAllCompleteHandle);
                dicAllScenes.Add(sceneName, multiABMgrObj);
            }

            MultiABMgr tmpMultiABMgr = dicAllScenes[sceneName];

            if (tmpMultiABMgr == null)
            {
                Debug.LogError(GetType() + "/LoadAssetBundlePack()/tmpMultiABMgr is Null!");
            }

            yield return(tmpMultiABMgr.LoadAssetBundle(abName));

            abInfo.AbState = EnumAbState.LoadFinish;
        }