public static bool ContainsEventPair(this List <EventPair> collection, EventPair toMatch) { if (toMatch.Left.Count == 1 && toMatch.Right.Count == 1) { foreach (var pair in collection) { if (pair.Left.Contains(toMatch.Left.First()) && pair.Right.Contains(toMatch.Right.First())) { return(true); } } return(false); } else { foreach (var pair in collection) { if (pair.Left.Intersect(toMatch.Left).Count() == toMatch.Left.Count() && pair.Right.Intersect(toMatch.Right).Count() == toMatch.Right.Count()) { return(true); } } return(false); } }
public static void Dispatch(string eventName, params object[] args) { if (_events.ContainsKey(eventName)) { List <EventPair> lst = _events[eventName]; for (int idx = 0; idx < lst.Count; ++idx) { EventPair ep = lst[idx]; ep.method.Invoke(ep.obj, args); } } }
public void Update() { if (null != m_lstEvent) { for (int i = 0; i < m_lstEvent.Count; i++) { EventPair child = m_lstEvent[i]; if (null == child) { continue; } if (null == child.Handle) { FireEvent(child.Type, child.Param); } else { child.Handle(child.Param); } } m_lstEvent.Clear(); } if (null != m_dictEvent) { dictClearList.Clear(); foreach (KeyValuePair <HandleEvent, TimeEventPair> kv in m_dictEvent) { TimeEventPair p = kv.Value; p.TimeMS -= (int)(Time.deltaTime * 1000f); if (p.TimeMS <= 0) { p.Handle(p.Param); dictClearList.Add(p.Handle); } } for (int i = 0; i < dictClearList.Count; ++i) { m_dictEvent.Remove(dictClearList[i]); } } }
public void Subscribe(string EventName, IEventSubscriber Subscriber) { bool been = false; for (int i=0; i<_pairs.Length; i++) { if (_pairs[i].Name == EventName) { _pairs[i].Events += Subscriber.OnEvent; been = true; break; } } if (!been) { EventPair x = new EventPair(); x.Name = EventName; x.Events = (a,b) => {}; x.Events += Subscriber.OnEvent; Array.Resize<EventPair>(ref _pairs,_pairs.Length+1); _pairs[_pairs.Length-1] = x; } }
public void AddListener <T>(GameObject go, Action <T> listener) where T : GameEvent { Type t = typeof(T); List <EventPair> listeners; if (!eventTable.TryGetValue(t, out listeners)) { listeners = new List <EventPair>(); eventTable.Add(t, listeners); } Action <GameEvent> action = (obj) => { var cast = (T)Convert.ChangeType(obj, t); listener(cast); }; var eventPair = new EventPair { go = go, eventAction = action }; listeners.Add(eventPair); }
public void Subscribe(string EventName, IEventSubscriber Subscriber) { bool been = false; for (int i = 0; i < _pairs.Length; i++) { if (_pairs[i].Name == EventName) { _pairs[i].Events += Subscriber.OnEvent; been = true; break; } } if (!been) { EventPair x = new EventPair(); x.Name = EventName; x.Events = (a, b) => {}; x.Events += Subscriber.OnEvent; Array.Resize <EventPair>(ref _pairs, _pairs.Length + 1); _pairs[_pairs.Length - 1] = x; } }
public static void Register(string eventName, object register, string funcName) { List <EventPair> lst = _events.ContainsKey(eventName) ? _events[eventName] : new List <EventPair>(); for (int i = 0; i < lst.Count; i++) { if (register.Equals(lst[i].obj) && lst[i].method.Name.Equals(funcName)) { return; } } EventPair ep = new EventPair(); ep.obj = register; ep.method = register.GetType().GetMethod(funcName); if (ep.method == null) { EDebug.LogErrorFormat("ZEventSystem register failed, obj {0} get method:{1} failed, no this method", register, funcName); return; } lst.Add(ep); _events[eventName] = lst; }
//this function has an important limitation: it can obtain the EventInfo ONLY //if the full property path up to the instance raising the event is uninterrupted (i.e. no null intances on the path) //at the time of initialization of the filter (which occurs very early in the lifetime of the ViewModel) EventPair GetEventPair(object rootObject, string eventPath) { if (rootObject== null) return null; var currentInstance = rootObject; var currentPath = eventPath; while (true) { var dotIndex = currentPath.IndexOf("."); if (dotIndex < 0) break; var propertyName = currentPath.Substring(0, dotIndex); if (string.IsNullOrEmpty(propertyName)) throw new ArgumentException(string.Format("Invalid event path", eventPath), "eventPath"); var propertyInfo = currentInstance.GetType().GetProperty(propertyName); if (propertyInfo == null) return null; currentInstance = propertyInfo.GetGetMethod().Invoke(currentInstance, new object[] { }); if (currentInstance==null) return null; if (dotIndex == currentPath.Length - 1) throw new ArgumentException(string.Format("Invalid event path", eventPath), "eventPath"); currentPath = currentPath.Substring(dotIndex + 1); } var pair = new EventPair { EventInfo = currentInstance.GetType().GetEvent(currentPath), Sender = currentInstance }; if (pair.EventInfo == null) pair = null; return pair; }
private List <EventPair> GetNormalizedPairs(List <EventPair> Hashes, List <EventPair> Forwards) { var x_w = Forwards.ToList(); var X_Temp = Forwards.ToList(); //Check if Hashes come with others foreach (var hash in Hashes) { var eventsToMatch = T_W.Where(t => t.Id != hash.Left.First().Id&& t.Id != hash.Right.First().Id).ToList(); foreach (var matchEvent in eventsToMatch) { var pairToMatch1 = new EventPair { Left = new List <Event> { matchEvent }, Right = new List <Event> { hash.Left.First() } }; var pairToMatch2 = new EventPair { Left = new List <Event> { matchEvent }, Right = new List <Event> { hash.Right.First() } }; if (X_Temp.ContainsEventPair(pairToMatch1) && X_Temp.ContainsEventPair(pairToMatch2)) { var eventPair = new EventPair { Left = new List <Event> { matchEvent }, Right = new List <Event> { pairToMatch1.Right.First(), pairToMatch2.Right.First() } }; if (!x_w.ContainsEventPair(eventPair)) { x_w.Add(eventPair); } } pairToMatch1 = new EventPair { Right = new List <Event> { matchEvent }, Left = new List <Event> { hash.Left.First() } }; pairToMatch2 = new EventPair { Right = new List <Event> { matchEvent }, Left = new List <Event> { hash.Right.First() } }; if (X_Temp.ContainsEventPair(pairToMatch1) && X_Temp.ContainsEventPair(pairToMatch2)) { var eventPair = new EventPair { Left = new List <Event> { pairToMatch1.Left.First(), pairToMatch2.Left.First() }, Right = new List <Event> { matchEvent } }; if (!x_w.ContainsEventPair(eventPair)) { x_w.Add(eventPair); } } } } return(x_w); }