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 static LSEffect GenEffect(string effectCode, int id = -1) { FastStack <LSEffect> pool; if (!EffectPool.TryGetValue(effectCode, out pool)) { return(null); } LSEffect effect = null; if (pool.Count > 0) { effect = pool.Pop(); } else { IEffectData dataItem = CodeDataMap [effectCode]; effect = GameObject.Instantiate <GameObject>(dataItem.GetEffect().gameObject).GetComponent <LSEffect>(); effect.Setup(effectCode); } if (id == -1) { id = GenerateID(); } if (effect.Create(id)) { return(effect); } else { return(GenEffect(effectCode, id)); } }
public void PrePoolEffect(IEffectData data, int prePoolCount) { string effectID = data.GetEffectID(); UnityComponentPool <EffectPlayerComponentBase> effectPool = GetOrCreatePool(data, effectID); effectPool.PrePooling(prePoolCount); }
private static LSEffect GenEffect(string effectCode, int id = -1) { FastStack <LSEffect> pool; if (!EffectPool.TryGetValue(effectCode, out pool)) { Debug.LogError(string.Format("Effect not found with code {0} in pool. Did you remember to add it to the Lockstep Database?", effectCode)); return(null); } LSEffect effect = null; if (pool.Count > 0) { effect = pool.Pop(); } else { IEffectData dataItem = CodeDataMap [effectCode]; effect = GameObject.Instantiate <GameObject>(dataItem.GetEffect().gameObject).GetComponent <LSEffect>(); effect.Setup(effectCode); } if (id == -1) { id = GenerateID(); } if (effect.Create(id)) { return(effect); } else { return(GenEffect(effectCode, id)); } }
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); }
public static void Setup() { IEffectDataProvider database; if (LSDatabaseManager.TryGetDatabase <IEffectDataProvider>(out database)) { IEffectData[] effectData = database.EffectData; EffectPool = new Dictionary <string, FastStack <LSEffect> >(effectData.Length); CodeDataMap = new Dictionary <string, IEffectData>(effectData.Length); for (int i = 0; i < effectData.Length; i++) { IEffectData dataItem = effectData [i]; string code = (string)dataItem.Name; EffectPool.Add(code, new FastStack <LSEffect>()); CodeDataMap.Add(code, dataItem); } } }
public static void AssertEqual(IEffectData expected, IEffectData actual) { Assert.AreEqual(expected.EffectType, actual.EffectType, "Different effect type."); Assert.AreEqual(expected.ShapeType, actual.ShapeType, "Different effect shape type."); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeRotation, actual.ShapeRotation), "Different effect shape rotation. exp:{0}, actual:{1}", expected.ShapeRotation, actual.ShapeRotation); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeWidth, actual.ShapeWidth), "Different effect shape width. exp:{0}, actual:{1}", expected.ShapeWidth, actual.ShapeWidth); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeHeight, actual.ShapeHeight), "Different effect shape height. exp:{0}, actual:{1}", expected.ShapeHeight, actual.ShapeHeight); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeLeft, actual.ShapeLeft), "Different effect shape left. exp:{0}, actual:{1}", expected.ShapeLeft, actual.ShapeLeft); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeTop, actual.ShapeTop), "Different effect shape top. exp:{0}, actual:{1}", expected.ShapeTop, actual.ShapeTop); Assert.IsTrue(SlideUtil.IsAlmostSame(expected.TimingTriggerDelayTime, actual.TimingTriggerDelayTime), "Different effect timing. exp:{0}, actual:{1}", expected.TimingTriggerDelayTime, actual.TimingTriggerDelayTime); }
public static void AssertEqual(IEffectData expected, IEffectData actual) { Assert.AreEqual(expected.EffectType, actual.EffectType, "Different effect type."); Assert.AreEqual(expected.ShapeType, actual.ShapeType, "Different effect shape type."); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeRotation, actual.ShapeRotation), "Different effect shape rotation. exp:{0}, actual:{1}", expected.ShapeRotation, actual.ShapeRotation); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeWidth, actual.ShapeWidth), "Different effect shape width. exp:{0}, actual:{1}", expected.ShapeWidth, actual.ShapeWidth); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeHeight, actual.ShapeHeight), "Different effect shape height. exp:{0}, actual:{1}", expected.ShapeHeight, actual.ShapeHeight); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeLeft, actual.ShapeLeft), "Different effect shape left. exp:{0}, actual:{1}", expected.ShapeLeft, actual.ShapeLeft); Assert.IsTrue(SlideUtil.IsRoughlySame(expected.ShapeTop, actual.ShapeTop), "Different effect shape top. exp:{0}, actual:{1}", expected.ShapeTop, actual.ShapeTop); Assert.IsTrue(SlideUtil.IsAlmostSame(expected.TimingTriggerDelayTime, actual.TimingTriggerDelayTime), "Different effect timing. exp:{0}, actual:{1}", expected.TimingTriggerDelayTime, actual.TimingTriggerDelayTime); }
public bool TryGetData(string effectID, out IEffectData data) => _data.TryGetValue(effectID, out data);
public EffectPlayCommand PlayEffect(IEffectData effectData) => GetEffect(effectData).PlayResource();
public EffectPlayCommand PlayEffect(IEffectData effectData) => _manager.PlayEffect(effectData);
public abstract void Execute(IEffectData data);
public override void Execute(IEffectData data) { throw new System.NotImplementedException(); }
public void PrePoolEffect(IEffectData data, int prePoolCount) => _manager.PrePoolEffect(data, prePoolCount);
public bool TryGetData(string effectID, out IEffectData data) => _manager.TryGetData(effectID, out data);
/// <summary> /// Initializes a new instance of the <see cref="Effect"/> class. /// </summary> /// <param name="data">The effect data.</param> /// <param name="objectsPool">The objects pool.</param> /// <param name="effectOwner">The effect owner (caster).</param> /// <exception cref="ArgumentNullException"> /// data /// or /// objectsPool /// or /// effectOwner /// </exception> public Effect(IEffectData data, IObjectsPool objectsPool, ITeamMember effectOwner) { this.data = data ?? throw new ArgumentNullException(nameof(data)); ObjectsPool = objectsPool ?? throw new ArgumentNullException(nameof(objectsPool)); Owner = effectOwner ?? throw new ArgumentNullException(nameof(effectOwner)); }
public EffectPlayCommand GetEffect(IEffectData data) => _manager.GetEffect(data);