示例#1
0
        public void Unsubscribe <T>(object tag, OnEvent <T> eventCallback)
        {
            var key = new DictionaryKey(tag, typeof(T));

            if (observerDictionary[key] != null)
            {
                observerDictionary[key].Remove(eventCallback.GetHashCode());
            }
        }
示例#2
0
        public void Subscribe <T>(object tag, OnEvent <T> eventCallback)
        {
            var key = new DictionaryKey(tag, typeof(T));

            if (!observerDictionary.ContainsKey(key))
            {
                observerDictionary[key] = new Dictionary <int, OnEventWrapper>();
            }

            observerDictionary[key][eventCallback.GetHashCode()] = (object _object) => { eventCallback((T)_object); };
        }
示例#3
0
        public void Dispatch <T>(object tag, T action)
        {
            var key = new DictionaryKey(tag, typeof(T));

            if (observerDictionary.ContainsKey(key))
            {
                foreach (var caller in observerDictionary[key].Values)
                {
                    caller(action);
                }
            }
            else
            {
                string tagAndAction = string.Format("(tag:{0}, action:{1})", tag, action);
                Debug.LogWarning("Unibus.Dispatch failed to send: " + tagAndAction);
            }
        }
示例#4
0
        public void Dispatch <T>(object tag, T action)
        {
            var key = new DictionaryKey(tag, typeof(T));

            if (observerDictionary.ContainsKey(key))
            {
                List <int> keys = new List <int>(observerDictionary[key].Keys);

                foreach (var k in keys)
                {
                    observerDictionary[key][k](action);
                }
            }
            else
            {
                string tagAndAction = string.Format("(tag:{0}, action:{1})", tag, action);
                // Отключил логирование. Оно только мешает.
                // Debug.LogWarning("Unibus.Dispatch failed to send: " + tagAndAction);
            }
        }
示例#5
0
        public void Dispatch <T>(object tag, T action)
        {
            var key = new DictionaryKey(tag, typeof(T));

            if (observerDictionary.ContainsKey(key))
            {
                List <OnEventWrapper> mTempList = null;
                foreach (var lst in mTempPooledList)
                {
                    if (lst.Count == 0)
                    {
                        mTempList = lst;
                        break;
                    }
                }
                if (mTempList == null)
                {
                    mTempList = new List <OnEventWrapper>();
                    mTempPooledList.Add(mTempList);
                    // Debug.Log($"pooled list size: {mTempPooledList.Count}");
                }
                foreach (var c in observerDictionary[key].Values)
                {
                    mTempList.Add(c);
                }
                foreach (var caller in mTempList)
                {
                    caller(action);
                }
                mTempList.Clear();
            }
            else
            {
                string tagAndAction = string.Format("(tag:{0}, action:{1})", tag, action);
                Debug.LogWarning("Unibus.Dispatch failed to send: " + tagAndAction);
            }
        }