public void ClearCaches() { _KeysToRemove.Clear(); foreach (var kv in _FxAssetCaches) { CFxCache fxCache = kv.Value; if (!fxCache.IsAutoClear) { continue; } if (kv.Value != null) { kv.Value.Clear(); } _KeysToRemove.Add(kv.Key); } foreach (var v in _KeysToRemove) { _FxAssetCaches.Remove(v); } _KeysToRemove.Clear(); }
public void PreloadFxAsset(string fxName) { if (!_FxAssetCaches.ContainsKey(fxName)) { var fxcache = new CFxCache(); fxcache.Init(fxName); fxcache.DeactiveTime = -1; fxcache.IsAutoClear = false; _FxAssetCaches.Add(fxName, fxcache); } }
public CFxOne RequestFxOne(string fxName, int priority, out int fxId) { // 超出上限,先关掉优先级最低的 #region 存量检查 if (_ActiveFxs.Count >= _MaxActiveFxCount) { int maxPriority = -1; int realCount = 0; for (int i = 0; i < _ActiveFxs.Count; ++i) { CFxOne fx = _ActiveFxs[i]; //-1 常驻 不参与计算 if (fx.Priority != -1) { if (fx.Priority > maxPriority) { maxPriority = fx.Priority; } ++realCount; } } if (realCount > _MaxActiveFxCount) { if (priority >= maxPriority) { fxId = 0; return(null); } // 关闭一个最低优先级的特效 for (int i = 0; i < _ActiveFxs.Count; ++i) { CFxOne fx1 = _ActiveFxs[i]; if (fx1.Priority == maxPriority) { fx1.Stop(); _ActiveFxs.Remove(fx1); break; } } } } #endregion // 检查资源缓存池 CFxCache fxcache = null; #region FxAssetCache_Area if (!_FxAssetCaches.TryGetValue(fxName, out fxcache)) { fxcache = new CFxCache(); fxcache.Init(fxName); _FxAssetCaches[fxName] = fxcache; } #endregion CFxOne fxone = GetEmptyFxOne(); #region GetFxOne_Area fxone.IsCached = true; fxone.ID = NewID(); //fxone.DontUseL3 = dontUseL3; var fxoneTrans = fxone.transform; fxoneTrans.parent = _ActiveFxsRootTrans; fxoneTrans.localPosition = Vector3.zero; fxoneTrans.localScale = Vector3.one; fxoneTrans.rotation = Quaternion.identity; #if UNITY_EDITOR fxone.Name = fxName; #endif fxone.Priority = priority; _ActiveFxs.Add(fxone); #endregion fxId = fxone.ID; if (!fxcache.Touch(fxone)) { RecycleFx(fxone); return(null); } return(fxone); }