public void LoadAsync(ResLoadInfo resLoadInfo) { if (resLoadInfo.mResPath == "") { AFLogger.e("资源路径为空,无法进行加载"); return; } ResInfo resInfo = ResManager.Instance.GetRes(resLoadInfo); if (resInfo != null && resInfo.State == ResState.Ready && (resInfo.ResObject.IsNotNull() || resInfo.ResStr.IsNotNullAndEmpty())) { resLoadInfo.mListener.InvokeGracefully(true, resInfo); } else if (resInfo == null) { resInfo = ResFactory.Create(resLoadInfo); //加入队列 if (resInfo.LoadAsync()) { ResManager.Instance.CacheResource(resLoadInfo.mResPath, resInfo); } } else { AFLogger.e("当前请求的资源正在加载,增加回调"); //当前请求的资源正在加载,增加回调 resInfo.RegisterListen(resLoadInfo.mListener); } }
/// <summary> /// 获取已经加载的资源 /// </summary> /// <param name="resLoadInfo"></param> /// <returns></returns> public ResInfo GetRes(ResLoadInfo resLoadInfo) { ResInfo resInfo = null; mResDictionary.TryGetValue(resLoadInfo.mCRC, out resInfo); return(resInfo); }
public static ResourcesRes Allocate(ResLoadInfo resLoadInfo) { ResourcesRes res = SafeObjectPool <ResourcesRes> .Instance.Allocate(); if (res != null) { res.Init(resLoadInfo); } return(res); }
public static NetImageRes Allocate(ResLoadInfo resLoadInfo) { NetImageRes res = SafeObjectPool <NetImageRes> .Instance.Allocate(); if (res != null) { res.Init(resLoadInfo); } return(res); }
public static EditorRes Allocate(ResLoadInfo resLoadInfo) { EditorRes res = SafeObjectPool <EditorRes> .Instance.Allocate(); if (res != null) { res.Init(resLoadInfo); } return(res); }
public virtual void Init(ResLoadInfo resLoadInfo) { mResPath = resLoadInfo.mResPath; mLoadRePriority = resLoadInfo.loadResPriority; DestroyCache = resLoadInfo.DestroyCache; isSprite = resLoadInfo.mIsSprite; resItem = new ResItem(); resItem.mCrc = Crc32.GetCrc32(mResPath); mListener = resLoadInfo.mListener; mResState = ResState.Waiting; }
public static ResLoadInfo Allocate(ObjLoadInfo objLoadInfo) { ResLoadInfo resLoadInfo = SafeObjectPool <ResLoadInfo> .Instance.Allocate(); resLoadInfo.mResPath = objLoadInfo.mResPath; resLoadInfo.mResFromType = objLoadInfo.mResFromType; resLoadInfo.mIsSprite = false; resLoadInfo.mListener = objLoadInfo.loadResCall; resLoadInfo.mCRC = Crc32.GetCrc32(objLoadInfo.mResPath); resLoadInfo.DestroyCache = objLoadInfo.mClear; return(resLoadInfo); }
/// <summary> /// 这里的mListen与调用loader传的参数并不相同 /// </summary> /// <param name="resType"></param> /// <param name="assetPath"></param> /// <param name="isSprite"></param> /// <param name="mListen"></param> /// <returns></returns> public static ResLoadInfo Allocate(ResFromType resType, string assetPath, bool isSprite, Action <bool, ResInfo> mListen = null, Action <bool, ResInfo> mRealListener = null, bool DestroyCache = false, LoadResPriority loadResPriority = LoadResPriority.RES_NUM) { ResLoadInfo resLoadInfo = SafeObjectPool <ResLoadInfo> .Instance.Allocate(); resLoadInfo.mResPath = assetPath; resLoadInfo.mResFromType = resType; resLoadInfo.mListener = mListen; resLoadInfo.mIsSprite = isSprite; resLoadInfo.DestroyCache = DestroyCache; resLoadInfo.loadResPriority = loadResPriority; resLoadInfo.mCRC = Crc32.GetCrc32(assetPath); resLoadInfo.mRealListener = mRealListener; return(resLoadInfo); }
/// <summary> /// 同步加载资源,这里不提供进度 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="resType">从哪里加载</param> /// <param name="assetPath"></param> /// <param name="isSprite">是否是加载Sprite</param> /// isRecycleOnDestroy : 当ResLoader被销毁时是否从内存中释放 /// <returns></returns> public T LoadSync <T>(ResFromType resType, string assetPath, bool isSprite = false, bool DestroyCache = false) where T : Object { if (CheckNoCanLoad()) { AFLogger.e("此Loader已经被释放,请注意!"); return(null); } ResLoadInfo resLoadInfo = ResLoadInfo.Allocate(resType, assetPath, isSprite, null, null, DestroyCache); Object resAsset = ResManager.Instance.LoadSync(resLoadInfo); if (resAsset != null) { //加载完成后添加到加载资源列表中 mResList.AddValue(resLoadInfo.mResPath); } resLoadInfo.Recycle2Cache(); return(resAsset as T); }
public void LoadResAsyncForObj(ObjLoadInfo objLoadInfo) { ResInfo resInfo = ResManager.Instance.GetRes(objLoadInfo.mCRC); if (resInfo == null) { ResLoadInfo resLoadInfo = ResLoadInfo.Allocate(objLoadInfo); //资源没有加载 LoadAsync(resLoadInfo); resLoadInfo.Recycle2Cache(); } else if (resInfo.State != ResState.Ready) { //资源正在加载,是其他loader的异步加载 resInfo.RegisterListen(objLoadInfo.loadResCall); } else { //资源已经加载完成,开始回调 objLoadInfo.loadResCall(true, resInfo); } }
/// <summary> /// 异步加载 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="resType"></param> /// <param name="assetPath"></param> /// <param name="loadFinish"></param> /// <param name="isSprite"></param> /// <param name="DestroyCache">当ResLoader被销毁时是否从内存中释放</param> /// <param name="loadResPriority">加载的优先级</param> public void LoadAsync <T>(ResFromType resType, string assetPath, System.Action <bool, ResInfo> loadFinish, bool isSprite = false, bool DestroyCache = false, LoadResPriority loadResPriority = LoadResPriority.RES_NUM) where T : Object { if (CheckNoCanLoad()) { AFLogger.e("此Loader已经被释放,请注意!"); return; } ResLoadInfo resLoadInfo = ResLoadInfo.Allocate(resType, assetPath, isSprite, AsyncResCallBack, loadFinish, DestroyCache); //添加回调函数 if (mAsyncLoadingResDic.ContainsKey(resLoadInfo.mResPath)) { mAsyncLoadingResDic[resLoadInfo.mResPath].Add(resLoadInfo); } else { AsyncCount += 1; mAsyncLoadingResDic.AddValue(resLoadInfo.mResPath, resLoadInfo); ResManager.Instance.LoadAsync(resLoadInfo); } }
/// <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 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); }
public void LoadAsync(ResLoadInfo resLoadInfo) { ResourceLoader.Instance.LoadAsync(resLoadInfo); }
public Object LoadSync(ResLoadInfo resLoadInfo) { return(ResourceLoader.Instance.LoadSync(resLoadInfo)); }
/// <summary> /// 加载Androidmanifest /// </summary> /// <returns></returns> public bool LoadAssetManifest() { AssetBundleConfig config = null; switch (ABConfig.configWritingMode) { case ConfigWritingMode.Binary: if (FileHelper.JudgeFilePathExit(GetABConfigLocalPath())) { if (configAB != null) { configAB.Unload(false); } configAB = AssetBundle.LoadFromFile(GetABConfigLocalPath()); TextAsset textAsset = configAB.LoadAsset <TextAsset>(ABConfigName); if (textAsset == null) { Debug.LogError("AssetBundleConfig is no exist!"); return(false); } //反序列化,得到打包的信息 MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); config = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); } else { AFLogger.e("AssetbundleConfig文件不存在"); return(false); } break; case ConfigWritingMode.TXT: string abJson = ""; if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB) { abJson = FileHelper.ReadTxtToStr(GetABConfigLocalPath()); if (abJson.Equals("")) { AFLogger.e("AssetbundleConfig文件不存在或者内容为空"); return(false); } } else if (ABConfig.ABResLoadfrom == ABResLoadFrom.StreamingAssetAB) { string abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName; TextAsset textAsset = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset; abJson = textAsset.text; } config = SerializeHelper.FromJson <AssetBundleConfig>(abJson); break; case ConfigWritingMode.XML: XmlDocument xml = new XmlDocument(); MemoryStream ms = null; if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB) { xml.Load(GetABConfigLocalPath()); } else { string abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName; TextAsset textAsset = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset; //由于编码问题,要设置编码方式 byte[] encodeString = System.Text.Encoding.UTF8.GetBytes(textAsset.text); //以流的形式来读取 ms = new MemoryStream(encodeString); xml.Load(ms); } if (xml == null) { AFLogger.e("AssetbundleConfig文件不存在或者内容为空"); return(false); } XmlSerializer xmldes = new XmlSerializer(typeof(AssetBundleConfig)); StringReader sr = new StringReader(xml.InnerXml); config = (AssetBundleConfig)xmldes.Deserialize(sr); if (ms != null) { ms.Close(); ms.Dispose(); } if (sr != null) { sr.Close(); sr.Dispose(); } break; } ResManager.Instance.CacheABConfig(config); return(true); }