예제 #1
0
        /// <summary>
        /// 释放加载器资源(如果强制删除或者计数为0则加入到待删除队列中)
        /// </summary>
        /// <param name="loader"></param>
        /// <param name="isForceDelete"></param>
        private static void ReleaseLoader(BaseAbstracResourceLoader loader, bool isForceDelete)
        {
            Queue <BaseAbstracResourceLoader> allUnUseLoadersOfType = null;

            if (S_UnUseLoader.TryGetValue(loader.GetType(), out allUnUseLoadersOfType) == false)
            {
                allUnUseLoadersOfType = new Queue <BaseAbstracResourceLoader>();
                S_UnUseLoader.Add(loader.GetType(), allUnUseLoadersOfType);
            }
            if (isForceDelete)
            {
                loader.ReleaseLoader();
                allUnUseLoadersOfType.Enqueue(loader);  //释放资源加载器资源并加入队列中
                return;
            }

            if (loader.ReferCount > 0)
            {
                Debug.LogInfor("DeleteLoader Fail,加载器的引用不为0,如果需要强制删除 请设置参数isForceDelete=true    ");
                return;
            }
            loader.ReleaseLoader();
            allUnUseLoadersOfType.Enqueue(loader);  //释放资源加载器资源并加入队列中
                                                    //  Debug.Log("回收加载器  " + typeof(T) + "::" + url + "  count=" + allUnUseLoadersOfType.Count);
        }
예제 #2
0
        /// <summary>
        ///  将Loader 删除放到不使用的字典中等待删除(需要判断引用计数是否小于1)
        /// </summary>
        /// <param name="loader">Loader.</param>
        public static void DeleteLoader(Type loaderType, string url, bool isForceDelete) //where T : BaseAbstracResourceLoader
        {
            BaseAbstracResourceLoader loader = DeleteExitLoaderInstanceFromRecord(loaderType, url);

            if (loader == null)
            {
                return;
            }

            ReleaseLoader(loader, isForceDelete);
        }
예제 #3
0
        public override void ReduceReference(BaseAbstracResourceLoader loader, bool isForcesDelete)
        {
#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                return;                                  //编辑器非运行情况不考虑
            }
#endif
            if (TryDeleteRecord(m_RequesterTarget))
            {
                base.ReduceReference(loader, isForcesDelete); //如果没有被记录过则添加引用计数
            }
        }
예제 #4
0
        /// <summary>
        /// 减少引用计数  (新增在减少引用计数的时候 如果资源没有加载完 则强制结束并释放资源)
        /// </summary>
        /// <param name="loader"></param>
        /// <param name="isForcesDelete"></param>
        public virtual void ReduceReference(BaseAbstracResourceLoader loader, bool isForcesDelete)
        {
            if (loader.IsCompleted == false)
            {
                Debug.LogEditorInfor(string.Format("资源(TypeLoader={0})在加载过程中被中断  url={1}", this.GetType(), m_ResourcesUrl));
                isForcesDelete = true;
                loader.ForceBreakLoaderProcess();
            }  //被中断的加载器

            --ReferCount;
            if (ReferCount <= 0 || isForcesDelete)
            {
                ResourcesLoaderMgr.DeleteLoader(loader.GetType(), m_ResourcesUrl, false);
            }//引用计数为0时候开始回收资源
        }
예제 #5
0
        /// <summary>
        /// 如果存在 则删除指定类型的加载器(只删除正在使用的加载器记录 不清理资源)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url"></param>
        private static BaseAbstracResourceLoader DeleteExitLoaderInstanceFromRecord(Type loaderType, string url)
        {
            BaseAbstracResourceLoader resultLoader = null;

            url = string.Format(@"{0}", url);
            Dictionary <string, BaseAbstracResourceLoader> typeOfLoaders = null;

            if (S_AllTypeLoader.TryGetValue(loaderType, out typeOfLoaders) == false)
            {
                return(null);
            }

            if (typeOfLoaders.ContainsKey(url) == false)
            {
                return(null);
            }

            resultLoader = typeOfLoaders[url];
            typeOfLoaders.Remove(url);
            return(resultLoader);
        }
 public override void ReduceReference(BaseAbstracResourceLoader loader, bool isForcesDelete)
 {
     //***这里不能有减少引用的操作  base.ReduceReference(loader, isForcesDelete);
 }