private UnityComponentPool <EffectPlayerComponentBase> GetOrCreatePool(IEffectData data, string effectID) { if (!_effectPoolByEffectID.TryGetValue(effectID, out var effectPool)) { EffectPlayerComponentBase effectPlayerOrigin = data.GetEffectPlayer(); if (effectPlayerOrigin == null) { Debug.LogError($"{nameof(EffectManager)} - data is EffectPlayerComponent is null (id:{effectID})"); } else { effectPool = new UnityComponentPool <EffectPlayerComponentBase>(effectPlayerOrigin); Transform poolParents = new GameObject().transform; if (_owner != null) { poolParents.SetParent(_owner.transform); } effectPool.SetParents(poolParents); _effectPoolByEffectID.Add(effectID, effectPool); } } return(effectPool); }
private void DespawnCommand(ResourcePlayCommandBase <IEffectPlayer> command) { _commandPool.DeSpawn(command as EffectPlayCommand); EffectPlayerComponentBase returnedPlayer = command.ResourcePlayer as EffectPlayerComponentBase; string returnedEffectID = returnedPlayer.GetEffectID(); if (_effectPoolByEffectID.TryGetValue(returnedEffectID, out var effectPoolForReturnedPlayer)) { effectPoolForReturnedPlayer.DeSpawn(returnedPlayer); } else { Debug.LogError($"{nameof(EffectManager)} - effectPlayer is not contain effectPool name:{returnedPlayer}, effectID:{returnedEffectID}", returnedPlayer); } }
public EffectPlayCommand GetEffect(IEffectData data) { string effectID = data.GetEffectID(); UnityComponentPool <EffectPlayerComponentBase> effectPool = GetOrCreatePool(data, effectID); EffectPlayerComponentBase unusedEffect = effectPool.Spawn(); unusedEffect.SetEffectID(effectID); EffectPlayCommand playCommand = _commandPool.Spawn(); playCommand.Init(unusedEffect, DespawnCommand); return(playCommand); }