public static void SetBinding(Subject.FnCallback fnCallback, KeyCode _key, KeyCode _keyModifier = KeyCode.None)
    {
        //If this event is already registered to some key binding
        if (Get().dictEventToBind.ContainsKey(fnCallback))
        {
            //Then Find that binding
            KeyBind curBind = Get().dictEventToBind [fnCallback];

            //And unregister the event currently linked to that binding
            //(The one we just consumed)
            Get().dictBindToEvent.Remove(curBind);
        }

        //Create the new desired binding
        KeyBind newBind = new KeyBind(_key, _keyModifier);

        if (Get().dictBindToEvent.ContainsKey(newBind))
        {
            //If this binding is already linked to an event

            //Fetch the event currently linked to that binding
            Subject.FnCallback curCallback = Get().dictBindToEvent[newBind];
            //And unbind it
            Get().dictEventToBind.Remove(curCallback);
        }

        Get().dictEventToBind [fnCallback] = newBind;
        Get().dictBindToEvent [newBind]    = fnCallback;
    }
Example #2
0
    public void StopObserving(Subject sub, Subject.FnCallback fnCallback)
    {
        for (int i = 0; i < lstObserving.Count; i++)
        {
            if (lstObserving[i].IsEqual(sub, fnCallback))
            {
                sub.UnSubscribe(fnCallback);
                lstObserving.RemoveAt(i);
                return;
            }
        }

        Debug.LogError("Error! Tried to stop observing " + sub + " with callback " + fnCallback + " but " + this + " wasn't subscribed to it");
    }
    public static void Unbind(KeyCode _key, KeyCode _keyModifier = KeyCode.None)
    {
        KeyBind newBind = new KeyBind(_key, _keyModifier);

        if (Get().dictBindToEvent.ContainsKey(newBind))
        {
            //If this binding is already linked to an event

            //then find that action bound to the binding
            Subject.FnCallback curCallback = Get().dictBindToEvent[newBind];

            //and remove it
            Get().dictEventToBind.Remove(curCallback);
        }

        //Now clear any function associated to that binding
        Get().dictBindToEvent.Remove(newBind);
    }
Example #4
0
 public void Observe(Subject sub, Subject.FnCallback fnCallback)
 {
     sub.Subscribe(fnCallback);
     lstObserving.Add(new ObservingInfo(sub, fnCallback));
 }
Example #5
0
 public bool IsEqual(Subject _subbedTo, Subject.FnCallback _fnCallback)
 {
     return(subbedTo == _subbedTo && fnCallback == _fnCallback);
 }
Example #6
0
 public ObservingInfo(Subject _subbedTo, Subject.FnCallback _fnCallback)
 {
     subbedTo   = _subbedTo;
     fnCallback = _fnCallback;
 }