/// <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); }
/// <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时候开始回收资源 }