/// <summary> /// 创建光效 /// </summary> /// <param name="nID"></param> /// <param name="param"></param> /// <returns></returns> public LightingEffectBehavior CreateEffect(int nID, LightEffectParam param, bool isFromHero = false) { if (!isValid) { return(null); } if (nID <= 0) { return(null); } LightingEffectBehavior reslut = null; LightingEffect config = ASpeedGame.Data.Scheme.SchemeLightingEffect.Instance.GetLightingEffect(nID); if (!config) { Trace.Warning("LightingEffect creates failed. Id " + nID.ToString() + "has not loaded."); return(reslut); } //if(!SceneManager.Instance.isMainCity()) //{ // if (!FirstCachedEffectID.Contains(nID)) // { // if (!currentCachedEffectID.Contains(nID)) // { // FirstCachedEffectID.Add(nID); // Debug.LogWarning("创建了没有缓存的光效,ID:" + nID); // } // } //} if (!isCanCreateEffect(config, param)) { return(reslut); } RemovePreWarmEffectQueue(nID); Queue <LightingEffectBehavior> cacheList = null; if (!m_behaviorCacheTable.TryGetValue(nID, out cacheList)) { cacheList = new Queue <LightingEffectBehavior>(); m_behaviorCacheTable.Add(nID, new Queue <LightingEffectBehavior>()); } if (cacheList.Count > 0) { reslut = cacheList.Dequeue(); ResetBehavior(reslut); } else { reslut = CreateNewBehavior(nID, config.GetEffectType()); } reslut.FillData(config, param, GetResourceHandleAsync(nID, reslut.OnResourcesLoadFinish), AllocBehaviorTransformAgent()); reslut.SetValid(); PushToEntityEffectTable(reslut); return(reslut); }
private bool PreWarmEffect(int nID, int PreWarmCount) { if (m_allBehaviorTable.ContainsKey(nID)) { //Debug.LogWarning("光效已经加载,不需要缓存,ID:" + nID); return(false); } LightingEffect config = ASpeedGame.Data.Scheme.SchemeLightingEffect.Instance.GetLightingEffect(nID); if (!config) { Debug.LogWarning("光效加载失败,找不到配置,ID:" + nID); return(false); } LightingEffectResHandle handle = AllocResourcesHandle(nID); Queue <LightingEffectBehavior> list = null; if (!m_behaviorCacheTable.TryGetValue(nID, out list)) { list = new Queue <LightingEffectBehavior>(); m_behaviorCacheTable.Add(nID, list); } for (int i = 0; i < PreWarmCount; i++) { LightingEffectBehavior reslut = CreateNewBehavior(nID, config.GetEffectType()); LightingEffectResHandleInstance instance = GetResourceHandleAsync(nID, reslut.OnResourcesLoadFinish); handle.CacheInstance(instance, EffectCacheRoot.transform, CachePos); handle.Release();//缓存不需要保留引用 reslut.FillData(config, null, instance, null); list.Enqueue(reslut); } return(true); }