/// <summary> /// 异步加载资源统一回调 /// </summary> /// <param name="LoadResult"></param> /// <param name="resInfo"></param> public void AsyncResCallBack(bool LoadResult, ResInfo resInfo) { AsyncCount -= 1; if (!LoadResult) { ResManager.Instance.RemoveLoadFailRes(resInfo.mCRC); resInfo.Recycle2Cache(); mAsyncLoadingResDic[resInfo.ResPath].ForEach((resLoadInfo) => { resLoadInfo.mRealListener.InvokeGracefully(LoadResult, null); resLoadInfo.Recycle2Cache(); }); mAsyncLoadingResDic.Remove(resInfo.ResPath); return; } bool DestroyCache = true; //异步加载回调 mAsyncLoadingResDic[resInfo.ResPath].ForEach((resLoadInfo) => { //但凡有一个调用此资源的说不销毁,就不销毁 if (!resLoadInfo.DestroyCache) { DestroyCache = false; } resInfo.Retain(); resLoadInfo.mRealListener.InvokeGracefully(LoadResult, resInfo); resLoadInfo.Recycle2Cache(); }); mAsyncLoadingResDic.Remove(resInfo.ResPath); resInfo.DestroyCache = DestroyCache; resInfo.mGUID = resInfo.ResObject.GetInstanceID(); mResList.AddValue(resInfo.ResPath); }
/// <summary> /// 同步加载资源 /// </summary> /// <param name="resLoadInfo"></param> /// <returns></returns> public Object LoadSync(ResLoadInfo resLoadInfo) { if (resLoadInfo.mResPath == "") { AFLogger.e("资源路径为空,无法进行加载"); return(null); } ResInfo resInfo = ResManager.Instance.GetRes(resLoadInfo); if (resInfo != null && resInfo.State == ResState.Ready && (resInfo.ResObject.IsNotNull() || resInfo.ResStr.IsNotNullAndEmpty())) { resInfo.Retain(); return(resInfo.ResObject); } else if (resInfo == null) { resInfo = ResFactory.Create(resLoadInfo); if (resInfo.LoadSync()) { resInfo.Retain(); Debug.Log("加载成功:" + resInfo.RefCount); ResManager.Instance.CacheResource(resLoadInfo.mResPath, resInfo); return(resInfo.ResObject); } else { //加载失败,释放 resInfo.Recycle2Cache(); } } else { AFLogger.e("同步遇到异步加载的资源 : " + resInfo.ResPath + ",请检查调用代码!"); } return(null); }
public void AsyncObjCallBack(bool LoadResult, ResInfo resInfo) { if (!LoadResult) { mAsyncLoadingObjDic.Remove(resInfo.ResPath); ResManager.Instance.RemoveLoadFailRes(resInfo.mCRC); resInfo.Recycle2Cache(); mAsyncLoadingObjDic[resInfo.ResPath].ForEach((objLoadInfo) => { objLoadInfo.loadObjCall.InvokeGracefully(LoadResult, null); objLoadInfo.Recycle2Cache(); }); mAsyncLoadingObjDic.Remove(resInfo.ResPath); return; } bool DestroyCache = false; mAsyncLoadingObjDic[resInfo.ResPath].ForEach((objLoadInfo) => { ResObject resObject = ResObject.Allocate(objLoadInfo); resObject.mObj = resInfo.ResObject; resObject.ABName = resInfo.ABName; resObject.mCloneObj = GameObject.Instantiate(resObject.mObj, objLoadInfo.ObjParentTrans) as GameObject; mObjList.AddValue(resObject.mCloneObj.GetInstanceID()); objLoadInfo.loadObjCall.InvokeGracefully(LoadResult, resObject); ResManager.Instance.CacheResObj(resObject); if (objLoadInfo.mClear) { DestroyCache = true; } resObject.Retain(); resInfo.Retain(); objLoadInfo.Recycle2Cache(); }); resInfo.DestroyCache = DestroyCache; mAsyncLoadingObjDic.Remove(resInfo.ResPath); }
public ResObject LoadResSyncForObj(ObjLoadInfo objLoadInfo) { ResObject resObject = ResObject.Allocate(objLoadInfo); ResInfo resInfo = ResManager.Instance.GetRes(objLoadInfo.mCRC); //之前就未加载 if (resInfo == null) { ResLoadInfo resLoadInfo = ResLoadInfo.Allocate(objLoadInfo); resObject.mObj = LoadSync(resLoadInfo); resLoadInfo.Recycle2Cache(); } //之前就加载完成 else if (resInfo.State == ResState.Ready) { resInfo.Retain(); resObject.mObj = resInfo.ResObject; } else { AFLogger.e("同步遇到异步正在或者等待加载的资源 : " + resInfo.ResPath + ",请检查调用代码!"); } return(resObject); }