Exemple #1
0
        public static Action On(string eventType, OnHandler handler)
        {
            // Note: User will need to register on domain reload...
            List <OnHandler> handlers = null;

            if (!s_Events.TryGetValue(eventType, out handlers))
            {
                handlers = new List <OnHandler> {
                    handler
                };
                s_Events.Add(eventType, handlers);
            }
            else if (handlers.Contains(handler))
            {
                throw new Exception("Cannot add existing event handler: " + eventType);
            }
            else
            {
                handlers.Add(handler);
            }

            return(() =>
            {
                Off(eventType, handler);
            });
        }
Exemple #2
0
        public static void Off(string eventType, OnHandler handler)
        {
            List <OnHandler> handlers = null;

            if (s_Events.TryGetValue(eventType, out handlers))
            {
                handlers.Remove(handler);
                if (handlers.Count == 0)
                {
                    s_Events.Remove(eventType);
                }
            }
        }
Exemple #3
0
    public static void Add(EventEnum type, OnHandler call)
    {
        MyList <OnHandler> list = EventDict[type];

        if (list == null)
        {
            list            = new MyList <OnHandler>();
            EventDict[type] = list;
        }
        if (list.IndexOf(call) != -1)
        {
            OnHandler handler = new OnHandler(call);
            handler += call;
            list.Push(handler);
        }
        //Event evt = new Event();
        //evt.OnHandler += Call;
    }
 public void Invoke(CustomEvent _event)
 {
     OnHandler?.Invoke(_event);
 }