public IRes GetRes(ResSearchRule resSearchRule, bool createNew = false) { IRes res = null; if (mResDictionary.TryGetValue(resSearchRule.DictionaryKey, out res)) { return(res); } if (!createNew) { Log.I("createNew:{0}", createNew); return(null); } res = ResFactory.Create(resSearchRule); if (res != null) { mResDictionary.Add(resSearchRule.DictionaryKey, res); if (!mResList.Contains(res)) { mResList.Add(res); } } return(res); }
public static IRes Create(ResSearchRule resSearchRule, short assetType) { switch (assetType) { case ResType.AssetBundle: return(AssetBundleRes.Allocate(resSearchRule.AssetName)); case ResType.ABAsset: return(AssetRes.Allocate(resSearchRule.AssetName, resSearchRule.OwnerBundle)); case ResType.ABScene: return(SceneRes.Allocate(resSearchRule.AssetName)); case ResType.Internal: return(ResourcesRes.Allocate(resSearchRule.AssetName, resSearchRule.AssetName.StartsWith("resources://") ? InternalResNamePrefixType.Url : InternalResNamePrefixType.Folder)); case ResType.NetImageRes: return(NetImageRes.Allocate(resSearchRule.AssetName)); case ResType.LocalImageRes: return(LocalImageRes.Allocate(resSearchRule.AssetName)); default: Log.E("Invalid assetType :" + assetType); return(null); } }
public static IRes Create(ResSearchRule resSearchRule) { var lowerAssetName = resSearchRule.AssetName.ToLower(); short assetType = 0; if (lowerAssetName.StartsWith("resources/") || lowerAssetName.StartsWith("resources://")) { assetType = ResType.Internal; } else if (lowerAssetName.StartsWith("netimage:")) { assetType = ResType.NetImageRes; } else if (lowerAssetName.StartsWith("localimage:")) { assetType = ResType.LocalImageRes; } else { var data = ResDatas.Instance.GetAssetData(resSearchRule); if (data == null) { Log.E("Failed to Create Res. Not Find AssetData:" + resSearchRule); return(null); } assetType = data.AssetType; } return(Create(resSearchRule, assetType)); }
public int AddAssetBundleName(string name, string[] depends) { if (string.IsNullOrEmpty(name)) { return(-1); } if (mABUnitArray == null) { mABUnitArray = new List <ABUnit>(); } var resSearchRule = ResSearchRule.Allocate(name); AssetData config = GetAssetData(resSearchRule); resSearchRule.Recycle2Cache(); if (config != null) { return(config.AssetBundleIndex); } mABUnitArray.Add(new ABUnit(name, depends)); int index = mABUnitArray.Count - 1; AddAssetData(new AssetData(name, ResType.AssetBundle, index, null)); return(index); }
private void AddRes2Array(IRes res, bool lastOrder) { var searchRule = ResSearchRule.Allocate(res.AssetName); //再次确保队列中没有它 var oldRes = FindResInArray(mResList, searchRule); searchRule.Recycle2Cache(); if (oldRes != null) { return; } res.Retain(); mResList.Add(res); if (res.State != ResState.Ready) { ++mLoadingCount; if (lastOrder) { mWaitLoadList.AddLast(res); } else { mWaitLoadList.AddFirst(res); } } }
protected void InitAssetBundleName() { mAssetBundleArray = null; var resSearchRule = ResSearchRule.Allocate(mAssetName, mOwnerBundleName); var config = ResDatas.Instance.GetAssetData(resSearchRule); resSearchRule.Recycle2Cache(); if (config == null) { Log.E("Not Find AssetData For Asset:" + mAssetName); return; } var assetBundleName = ResDatas.Instance.GetAssetBundleName(config.AssetName, config.AssetBundleIndex, mOwnerBundleName); if (string.IsNullOrEmpty(assetBundleName)) { Log.E("Not Find AssetBundle In Config:" + config.AssetBundleIndex + mOwnerBundleName); return; } mAssetBundleArray = new string[1]; mAssetBundleArray[0] = assetBundleName; }
public void Add2Load(string ownerBundle, string assetName, Action <bool, IRes> listener = null, bool lastOrder = true) { var searchRule = ResSearchRule.Allocate(assetName, ownerBundle); Add2Load(searchRule, listener, lastOrder); searchRule.Recycle2Cache(); }
/// <summary> /// ID:RKRL003 只通过资源名字进行同步加载, /// </summary> /// <param name="name">资源名字</param> /// <returns></returns> public Object LoadSync(string name) { var resSearchRule = ResSearchRule.Allocate(name); var retAsset = DoLoadSync(resSearchRule); resSearchRule.Recycle2Cache(); return(retAsset); }
/// <summary> /// ID:RKRL003 同步加载AssetBundle里的资源 ResLoader.LoadSync<T>(string ownerBundle,string assetBundle) /// </summary> /// <param name="ownerBundle">assetBundle名字</param> /// <param name="assetName">资源名字</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public T LoadSync <T>(string ownerBundle, string assetName) where T : Object { var resSearchRule = ResSearchRule.Allocate(assetName, ownerBundle, typeof(T).ToString()); var retAsset = DoLoadSync(resSearchRule); resSearchRule.Recycle2Cache(); return(retAsset as T); }
public void Add2Load(List <string> list) { if (list == null) { return; } for (var i = list.Count - 1; i >= 0; --i) { var resSearchRule = ResSearchRule.Allocate(list[i]); Add2Load(resSearchRule); resSearchRule.Recycle2Cache(); } }
public AssetData GetAssetData(ResSearchRule resSearchRule) { for (var i = mActiveAssetDataGroup.Count - 1; i >= 0; --i) { var result = mActiveAssetDataGroup[i].GetAssetData(resSearchRule); if (result == null) { continue; } return(result); } return(null); }
public bool AddAssetData(AssetData data) { if (mAssetDataMap == null) { mAssetDataMap = new Dictionary <string, AssetData>(); } if (mUUID4AssetData == null) { mUUID4AssetData = new Dictionary <string, AssetData>(); } string key = data.AssetName.ToLower(); if (mAssetDataMap.ContainsKey(key)) { var resSearchRule = ResSearchRule.Allocate(data.AssetName); var old = GetAssetData(resSearchRule); resSearchRule.Recycle2Cache(); try { Log.E("Already Add AssetData :{0} \n OldAB:{1} NewAB:{2}", data.AssetName, mABUnitArray[old.AssetBundleIndex].abName, mABUnitArray[data.AssetBundleIndex].abName); } catch (Exception e) { Debug.LogWarning(e); } } else { mAssetDataMap.Add(key, data); } if (mUUID4AssetData.ContainsKey(data.UUID)) { var resSearchRule = ResSearchRule.Allocate(data.AssetName, data.OwnerBundleName); AssetData old = GetAssetData(resSearchRule); resSearchRule.Recycle2Cache(); Log.E("Already Add AssetData :{0} \n OldAB:{1} NewAB:{2}", data.UUID, mABUnitArray[old.AssetBundleIndex].abName, mABUnitArray[data.AssetBundleIndex].abName); } else { mUUID4AssetData.Add(data.UUID, data); } return(true); }
private Object DoLoadSync(ResSearchRule resSearchRule) { Add2Load(resSearchRule); LoadSync(); var res = ResMgr.Instance.GetRes(resSearchRule, false); if (res == null) { Log.E("Failed to Load Res:" + resSearchRule); return(null); } return(res.Asset); }
public AssetData GetAssetData(ResSearchRule resSearchRule) { AssetData result = null; if (resSearchRule.OwnerBundle != null && mUUID4AssetData != null) { return(mUUID4AssetData.TryGetValue(resSearchRule.DictionaryKey, out result) ? result : null); } if (resSearchRule.OwnerBundle == null && mAssetDataMap != null) { return(mAssetDataMap.TryGetValue(resSearchRule.DictionaryKey, out result) ? result : null); } return(result); }
private static IRes FindResInArray(List <IRes> list, ResSearchRule resSearchRule) { if (list == null) { return(null); } for (var i = list.Count - 1; i >= 0; --i) { if (resSearchRule.Match(list[i])) { return(list[i]); } } return(null); }
private void Add2Load(ResSearchRule resSearchRule, Action <bool, IRes> listener = null, bool lastOrder = true) { var res = FindResInArray(mResList, resSearchRule); if (res != null) { if (listener != null) { AddResListenerRecord(res, listener); res.RegisteResListener(listener); } return; } res = ResMgr.Instance.GetRes(resSearchRule, true); if (res == null) { return; } if (listener != null) { AddResListenerRecord(res, listener); res.RegisteResListener(listener); } //无论该资源是否加载完成,都需要添加对该资源依赖的引用 var depends = res.GetDependResList(); if (depends != null) { foreach (var depend in depends) { var searchRule = ResSearchRule.Allocate(depend); Add2Load(searchRule); searchRule.Recycle2Cache(); } } AddRes2Array(res, lastOrder); }
public void ReleaseRes(string resName) { if (string.IsNullOrEmpty(resName)) { return; } #if UNITY_EDITOR if (Res.SimulateAssetBundleInEditor) { if (mCachedSpriteDict.ContainsKey(resName)) { var sprite = mCachedSpriteDict[resName]; GameObject.Destroy(sprite); mCachedSpriteDict.Remove(resName); } } #endif var resSearchRule = ResSearchRule.Allocate(resName); var res = ResMgr.Instance.GetRes(resSearchRule); resSearchRule.Recycle2Cache(); if (res == null) { return; } if (mWaitLoadList.Remove(res)) { --mLoadingCount; if (mLoadingCount == 0) { mListener = null; } } if (mResList.Remove(res)) { res.UnRegisteResListener(OnResLoadFinish); res.Release(); ResMgr.Instance.ClearOnUpdate(); } }
public ABUnit GetABUnit(string assetName) { var resSearchRule = ResSearchRule.Allocate(assetName); AssetData data = GetAssetData(resSearchRule); resSearchRule.Recycle2Cache(); if (data == null) { return(null); } if (mABUnitArray == null) { return(null); } return(mABUnitArray[data.AssetBundleIndex]); }
protected void UnHoldDependRes() { var depends = GetDependResList(); if (depends == null || depends.Length == 0) { return; } for (var i = depends.Length - 1; i >= 0; --i) { var resSearchRule = ResSearchRule.Allocate(depends[i]); var res = ResMgr.Instance.GetRes(resSearchRule, false); resSearchRule.Recycle2Cache(); if (res != null) { res.Release(); } } }
public bool IsDependResLoadFinish() { var depends = GetDependResList(); if (depends == null || depends.Length == 0) { return(true); } for (var i = depends.Length - 1; i >= 0; --i) { var resSearchRule = ResSearchRule.Allocate(depends[i]); var res = ResMgr.Instance.GetRes(resSearchRule, false); resSearchRule.Recycle2Cache(); if (res == null || res.State != ResState.Ready) { return(false); } } return(true); }