Пример #1
0
        public void StartListening(string eventName, UnityAction <ParamsObject> listener)
        {
            if (eventDictionary == null)
            {
                eventDictionary = new Dictionary <string, ParamsEvent>();
                lastEventValues = new Dictionary <string, ParamsObject>();
            }

            ParamsEvent thisEvent = null;

            if (eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.AddListener(listener);
            }
            else
            {
                thisEvent = new ParamsEvent();
                thisEvent.AddListener(listener);
                eventDictionary.Add(eventName, thisEvent);
            }

            ParamsObject paramsObj = null;

            if (lastEventValues != null && lastEventValues.TryGetValue(eventName, out paramsObj))
            {
                if (paramsObj != null)
                {
                    listener.Invoke(paramsObj);
                }
            }
        }
Пример #2
0
        public static void StartListening(string eventName, UnityAction <ParamsObject> listener)
        {
            ParamsEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.AddListener(listener);
            }
            else
            {
                thisEvent = new ParamsEvent();
                thisEvent.AddListener(listener);
                instance.eventDictionary.Add(eventName, thisEvent);
            }

            ParamsObject paramsObj = null;

            if (instance.lastEventValues != null && instance.lastEventValues.TryGetValue(eventName, out paramsObj))
            {
                if (paramsObj != null)
                {
                    listener.Invoke(paramsObj);
                }
            }
        }
Пример #3
0
        public void StopListening(string eventName, UnityAction <ParamsObject> listener)
        {
            ParamsEvent thisEvent = null;

            if (eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.RemoveListener(listener);
            }
        }
Пример #4
0
    void Start()
    {
        myEvent = new UnityEvent();
        myEvent.AddListener(FireFunction);
        myEvent.AddListener(AnotherFireFunction);

        paramsEvent = new ParamsEvent();
        paramsEvent.AddListener(FireFunctionWithParams);

        myEvent.Invoke();
        paramsEvent.Invoke("hello", 22);
        paramsEvent.Invoke("jdawgs", 8008135);
    }
Пример #5
0
        public static void StopListening(string eventName, UnityAction <ParamsObject> listener)
        {
            if (eventManager == null)
            {
                return;
            }
            ParamsEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.RemoveListener(listener);
            }
        }
Пример #6
0
        public static void TriggerEvent(string eventName, ParamsObject paramsObj = null)
        {
            ParamsEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.Invoke(paramsObj);
            }

            if (instance.lastEventValues != null)
            {
                instance.lastEventValues[eventName] = paramsObj;
            }
        }
Пример #7
0
        public void TriggerEvent(string eventName, ParamsObject paramsObj = null)
        {
            if (eventDictionary == null)
            {
                eventDictionary = new Dictionary <string, ParamsEvent>();
                lastEventValues = new Dictionary <string, ParamsObject>();
            }

            ParamsEvent thisEvent = null;

            if (eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.Invoke(paramsObj);
                lastEventValues[eventName] = paramsObj;
            }
        }
Пример #8
0
 public bool RegisterEvent(string key, UnityAction <object[]> listener)
 {
     if (eventMap.ContainsKey(key))
     {
         ParamsEvent paramsEvent;
         if (eventMap.TryGetValue(key, out paramsEvent))
         {
             //functionPrototype += eventFunction;
             paramsEvent.AddListener(listener);
             //eventMap[key] = functionPrototype;
         }
     }
     else
     {
         //ParamsEvent functionPrototype = eventFunction;
         ParamsEvent newEvent = new ParamsEvent();
         newEvent.AddListener(listener);
         eventMap.Add(key, newEvent);
     }
     return(true);
 }