Beispiel #1
0
    private NonGenericEventDelegate AddDelegate <T>(EventDelegate <T> del) where T : GameEvent
    {
        // Early-out if we've already registered this delegate
        if (delegateLookup.ContainsKey(del))
        {
            return(null);
        }

        // Create a new non-generic delegate which calls our generic one.
        // This is the delegate we actually invoke.
        NonGenericEventDelegate internalDelegate = (GameEvent evt) => {
            del.Invoke(evt as T);
        };

        delegateLookup[del] = internalDelegate;
        Type type = typeof(T);

        NonGenericEventDelegate tempDel;

        if (delegates.TryGetValue(type, out tempDel))
        {
            delegates[type] = tempDel += internalDelegate;
        }
        else
        {
            delegates[type] = internalDelegate;
        }

        return(internalDelegate);
    }
Beispiel #2
0
    public void AddListenerOnce <T>(EventDelegate <T> del) where T : GameEvent
    {
        NonGenericEventDelegate result = AddDelegate <T>(del);

        if (result != null)
        {
            // remember this is only called once
            onceLookups[result] = true;
        }
    }
Beispiel #3
0
    public void AddListenerOnce <T>(EventDelegate <T> del) where T : GameEvent
    {
        EventDelegate <T> fn = null;

        fn = (T evt) => {
            del(evt);
            RemoveListener(fn);
        };
        NonGenericEventDelegate result = AddDelegate(fn);
    }