/// <summary> /// Dispose是有引用检查的, DoDispose一般用于继承重写 /// </summary> public void Dispose() { if (DisposeEvent != null) { DisposeEvent(); } if (!IsForceNew) { var type = GetType(); var typeDict = ABManager.GetTypeDict(type); if (Url != null) { var bRemove = typeDict.Remove(Url); if (!bRemove) { Log.Warning("[{0}:Dispose]No Url: {1}, Cur RefCount: {2}", type.Name, Url, RefCount); } } } if (IsCompleted) { DoDispose(); } // 未完成,在OnFinish时会执行DoDispose }
/// <summary> /// 统一的对象工厂 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url"></param> /// <param name="callback"></param> /// <param name="forceCreateNew"></param> /// <returns></returns> protected static T AutoNew <T>(string url, LoaderDelgate callback = null, bool forceCreateNew = false, params object[] initArgs) where T : AbstractResourceLoader, new() { if (string.IsNullOrEmpty(url)) { Log.Error("[{0}:AutoNew]url为空", typeof(T)); return(null); } Dictionary <string, AbstractResourceLoader> typesDict = ABManager.GetTypeDict(typeof(T)); AbstractResourceLoader loader; typesDict.TryGetValue(url, out loader); if (forceCreateNew || loader == null) { loader = new T(); if (!forceCreateNew) { typesDict[url] = loader; } loader.IsForceNew = forceCreateNew; loader.Init(url, initArgs); if (Application.isEditor) { KResourceLoaderDebugger.Create(typeof(T).Name, url, loader); } } else if (loader != null && loader.IsCompleted && loader.IsError) { loader.Init(url, initArgs); } else { if (loader.RefCount < 0) { //loader.IsDisposed = false; // 转死回生的可能 Log.Error("Error RefCount!"); } } loader.RefCount++; // RefCount++了,重新激活,在队列中准备清理的Loader if (ABManager.UnUsesLoaders.ContainsKey(loader)) { ABManager.UnUsesLoaders.Remove(loader); loader.Revive(); } loader.AddCallback(callback); return(loader as T); }