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()); } }
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); }; }
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); } }
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); } }
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); } }