/// <summary> /// 放回池里,并不销毁 /// </summary> public void PushEffect(VFXEffectInstance effect) { if (effect.Instance) { int vfxTypeIndex = (int)effect.VFXType; effect.Instance.SetActive(false); effect.Instance.transform.SetParent(transform, false); m_EffectStates[vfxTypeIndex].InstantiatePool.Push(effect); } }
void LateUpdate() { if (Input.GetKeyDown(KeyCode.F5)) { VFXManager.GetInstance().PushEffect(m_Effect1); VFXManager.GetInstance().PushEffect(m_Effect2); } if (Input.GetKeyDown(KeyCode.F6)) { m_Effect1 = VFXManager.GetInstance().PopEffect(VFXConfig.VFXType.Effect_1); m_Effect2 = VFXManager.GetInstance().PopEffect(VFXConfig.VFXType.Effect_1); } }
/// <summary> /// 异步创建Effect /// <see cref="GetEffectCountInPool(VFXConfig.VFXType)"/>大于0的话从池中拿 /// 异步实例化 /// </summary> public void PopEffectAsync(VFXConfig.VFXType vfxType, Action <VFXEffectInstance> completedAction) { int vfxTypeIndex = (int)vfxType; if (m_EffectStates[vfxTypeIndex].InstantiatePool.Count > 0) { VFXEffectInstance effectInstance = m_EffectStates[vfxTypeIndex].InstantiatePool.Pop(); effectInstance.Instance.SetActive(true); completedAction?.Invoke(effectInstance); } else { m_EffectStates[vfxTypeIndex].PopCompletedActions.Enqueue(completedAction); m_AssetHelper.InstantiateEffectAsync(vfxType, OnInstantiateEffectCompleted); } }
/// <summary> /// 同步创建Effect /// <see cref="GetEffectCountInPool(VFXConfig.VFXType)"/>大于0的话从池中拿 /// <see cref="IsLoadedEffect(VFXConfig.VFXType)"/>的话,通过Loaded出来的Effect实例化 /// </summary> public VFXEffectInstance PopEffect(VFXConfig.VFXType vfxType) { if (GetEffectCountInPool(vfxType) > 0) { VFXEffectInstance effectInstance = m_EffectStates[(int)vfxType].InstantiatePool.Pop(); effectInstance.Instance.SetActive(true); return(effectInstance); } else if (IsLoadedEffect(vfxType)) { m_EffectStates[(int)vfxType].InstantiateCount++; return(new VFXEffectInstance(vfxType, Instantiate(m_AssetHelper.GetEffect(vfxType)), false)); } else { throw new Exception(string.Format("effect ({0}) not loaded", vfxType)); } }
private void OnPopEffect2(VFXEffectInstance obj) { m_Effect2 = obj; }