diff --git a/Assets/TEngine/Runtime/ECS/ECSEventCmpt.cs b/Assets/TEngine/Runtime/ECS/ECSEventCmpt.cs index 7e60ddd6..2327b482 100644 --- a/Assets/TEngine/Runtime/ECS/ECSEventCmpt.cs +++ b/Assets/TEngine/Runtime/ECS/ECSEventCmpt.cs @@ -5,170 +5,78 @@ namespace TEngine { public class ECSEventCmpt : ECSComponent { - private Dictionary m_eventDic = new Dictionary(); + private GameEvent _gameEvent; #region AddEventListener - public void AddEventListener(int eventid, Action action) + public void AddEventListener(int eventId, Action action) { - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions += action; - } - else - { - m_eventDic.Add(eventid, new EcsEventInfo(action)); - } + _gameEvent.AddEventListener(eventId, action); } - public void AddEventListener(int eventid, Action action) + public void AddEventListener(int eventId, Action action) { - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions += action; - } - else - { - m_eventDic.Add(eventid, new EcsEventInfo(action)); - } + _gameEvent.AddEventListener(eventId, action); } - public void AddEventListener(int eventid, Action action) + public void AddEventListener(int eventId, Action action) { - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions += action; - } - else - { - m_eventDic.Add(eventid, new EcsEventInfo(action)); - } + _gameEvent.AddEventListener(eventId, action); } - public void AddEventListener(int eventid, Action action) + public void AddEventListener(int eventId, Action action) { - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions += action; - } - else - { - m_eventDic.Add(eventid, new EcsEventInfo(action)); - } + _gameEvent.AddEventListener(eventId, action); } #endregion #region RemoveEventListener - public void RemoveEventListener(int eventid, Action action) + public void RemoveEventListener(int eventId, Action action) { - if (action == null) - { - return; - } - - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions -= action; - } + _gameEvent.RemoveEventListener(eventId, action); } - public void RemoveEventListener(int eventid, Action action) + public void RemoveEventListener(int eventId, Action action) { - if (action == null) - { - return; - } - - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions -= action; - } + _gameEvent.RemoveEventListener(eventId, action); } - public void RemoveEventListener(int eventid, Action action) + public void RemoveEventListener(int eventId, Action action) { - if (action == null) - { - return; - } - - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions -= action; - } + _gameEvent.RemoveEventListener(eventId, action); } - public void RemoveEventListener(int eventid, Action action) + public void RemoveEventListener(int eventId, Action action) { - if (action == null) - { - return; - } - - if (m_eventDic.ContainsKey(eventid)) - { - (m_eventDic[eventid] as EcsEventInfo).actions -= action; - } + _gameEvent.RemoveEventListener(eventId, action); } #endregion #region Send - public void Send(int eventid, T info) + public void Send(int eventId, T info) { - if (m_eventDic.ContainsKey(eventid)) - { - var EcsEventInfo = (m_eventDic[eventid] as EcsEventInfo); - if (EcsEventInfo != null) - { - EcsEventInfo.actions.Invoke(info); - } - } + _gameEvent.Send(eventId, info); } - public void Send(int eventid, T info, U info2) + public void Send(int eventId, T info, U info2) { - if (m_eventDic.ContainsKey(eventid)) - { - var EcsEventInfo = (m_eventDic[eventid] as EcsEventInfo); - if (EcsEventInfo != null) - { - EcsEventInfo.actions.Invoke(info, info2); - } - } + _gameEvent.Send(eventId, info, info2); } - public void Send(int eventid, T info, U info2, W info3) + public void Send(int eventId, T info, U info2, W info3) { - if (m_eventDic.ContainsKey(eventid)) - { - var EcsEventInfo = (m_eventDic[eventid] as EcsEventInfo); - if (EcsEventInfo != null) - { - EcsEventInfo.actions.Invoke(info, info2, info3); - } - } + _gameEvent.Send(eventId, info, info2, info3); } - /// - /// 事件触发 无参 - /// - /// - public void Send(int eventid) + public void Send(int eventId) { - if (m_eventDic.ContainsKey(eventid)) - { - var EcsEventInfo = (m_eventDic[eventid] as EcsEventInfo); - if (EcsEventInfo != null) - { - EcsEventInfo.actions.Invoke(); - } - } + _gameEvent.Send(eventId); } #endregion #region Clear public void Clear() { - m_eventDic.Clear(); + GameMemPool.Free(_gameEvent); } #endregion @@ -180,57 +88,9 @@ namespace TEngine public override void Awake() { + _gameEvent = GameMemPool.Alloc(); Entity.Event = this; } #endregion } - - #region EcsEventInfo - internal interface IEcsEcsEventInfo - { - - } - - public class EcsEventInfo : IEcsEcsEventInfo - { - public Action actions; - - public EcsEventInfo(Action action) - { - actions += action; - } - } - - - public class EcsEventInfo : IEcsEcsEventInfo - { - public Action actions; - - public EcsEventInfo(Action action) - { - actions += action; - } - } - - public class EcsEventInfo : IEcsEcsEventInfo - { - public Action actions; - - public EcsEventInfo(Action action) - { - actions += action; - } - } - - public class EcsEventInfo : IEcsEcsEventInfo - { - public Action actions; - - public EcsEventInfo(Action action) - { - actions += action; - } - } - #endregion - } \ No newline at end of file