public void ReduceRef(string url) { if (string.IsNullOrEmpty(url)) { LogModule.ErrorLog("BaseResCached.ReduceRef called but url is IsNullOrEmpty!"); return; } if (!_cachedBundleDic.ContainsKey(url)) { LogModule.ErrorLog("BaseResCached.ReduceRef called but url {0} is not in cached!!", url); return; } SCachedBundleData data = _cachedBundleDic[url]; data.RefCount--; _cachedBundleDic[url] = data; }
/// <summary> /// 增加引用 /// </summary> /// <param name="url"></param> public void AddRef(string url) { if (string.IsNullOrEmpty(url)) { LogModule.ErrorLog("BaseResCached.AddRef called but url is IsNullOrEmpty!"); return; } if (!_cachedBundleDic.ContainsKey(url)) { LogModule.ErrorLog("BaseResCached.AddRef called but url {0} is not in cached!!", url); return; } SCachedBundleData data = _cachedBundleDic[url]; data.RefCount++; data.LastAccessTime = Time.realtimeSinceStartup; _cachedBundleDic[url] = data; }
public bool Update() { float curTime = Time.realtimeSinceStartup; var enumerator = _cachedBundleDic.GetEnumerator(); while (enumerator.MoveNext()) { if (_curIndex >= MaxClearCountPreFrame) { break; } SCachedBundleData data = enumerator.Current.Value; if (data.RefCount <= 0 && curTime - data.LastAccessTime > MaxClearTime) { _needToRemoveArray[_curIndex] = enumerator.Current.Key; _curIndex++; } } bool res = _needToUnloadUnusedAssetNextFrame; _needToUnloadUnusedAssetNextFrame = ClearCurFrameCache(); _lastTickTime = Time.realtimeSinceStartup; return(res); }