예제 #1
0
    public void RemoveEventListener(EventDefine.EventId eventId, Action <GameEvent> act)
    {
        ushort id = (ushort)eventId;

        if (!eventDictionary.ContainsKey(id))
        {
            Debug.LogWarning("尝试移除不存在的监听");
            return;
        }

        var list = eventDictionary[id];

        if (!list.Contains(act))
        {
            Debug.LogWarning("尝试移除不存在的监听");
        }
        else
        {
            list.Remove(act);
            if (list.Count == 0)
            {
                eventDictionary.Remove(id);
            }
        }
    }
예제 #2
0
    public void SendEvent(EventDefine.EventId eventId, GameEvent gameEvent)
    {
        ushort id = (ushort)eventId;

        if (!eventDictionary.ContainsKey(id))
        {
            Debug.LogWarning($"没有监听 id:{id.ToString()}");
            return;
        }

        var actList = eventDictionary[id];

        for (int i = 0; i < actList.Count; i++)
        {
            actList[i](gameEvent);
        }
    }
예제 #3
0
    public void AddEventListener(EventDefine.EventId eventId, Action <GameEvent> act)
    {
        ushort id = (ushort)eventId;

        if (!eventDictionary.ContainsKey(id))
        {
            var list = new List <Action <GameEvent> >();
            eventDictionary.Add(id, list);
        }

        var actList = eventDictionary[id];

        if (!actList.Contains(act))
        {
            actList.Add(act);
        }
        else
        {
            Debug.LogWarning("重复添加监听");
        }
    }
예제 #4
0
 public GameEvent(EventDefine.EventId eventId)
 {
     id = (ushort)eventId;
 }