コード例 #1
0
    public static void RemoveInputListener <T>(this IInputReceiver r, InputTransmitter.EventDelegate <T> callback)
        where T : InputEvent
    {
        if (r.Delegates == null)
        {
            return;
        }

        InputTransmitter.EventDelegate internalDel;

        if (r.DelegateLookUp.TryGetValue(callback, out internalDel))
        {
            InputTransmitter.EventDelegate tempDel;
            if (r.Delegates.TryGetValue(typeof(T), out tempDel))
            {
                tempDel -= internalDel;

                if (tempDel == null)
                {
                    r.Delegates.Remove(typeof(T));
                }
                else
                {
                    r.Delegates[typeof(T)] = tempDel;
                }
            }

            r.DelegateLookUp.Remove(callback);
        }
    }
コード例 #2
0
    public static void AddInputListener <T>(this IInputReceiver r, InputTransmitter.EventDelegate <T> callback)
        where T : InputEvent
    {
        if (r.Delegates == null)
        {
            r.Delegates = new Dictionary <Type, InputTransmitter.EventDelegate>();
        }

        if (r.DelegateLookUp == null)
        {
            r.DelegateLookUp = new Dictionary <Delegate, InputTransmitter.EventDelegate>();
        }

        if (r.DelegateLookUp.ContainsKey(callback))
        {
            return;
        }

        InputTransmitter.EventDelegate del = (e) => callback((T)e);
        r.DelegateLookUp[callback] = del;

        InputTransmitter.EventDelegate tempDel;

        if (r.Delegates.TryGetValue(typeof(T), out tempDel))
        {
            r.Delegates[typeof(T)] = tempDel += del;
        }
        else
        {
            r.Delegates.Add(typeof(T), del);
        }

        if (r.AttachedInputTransmitterList == null)
        {
            r.AttachedInputTransmitterList = new List <InputTransmitter>();
        }
    }