private static void _fire(HandleTable handles, LinkedList <EventObj> firedEvents, string eventname, object[] args) { handles.Lock(); List <Pair> lst; if (!handles.TryGetValue(eventname, out lst)) { handles.UnLock(); return; } Debug.Log("fire 1:" + eventname); for (int i = 0; i < lst.Count; i++) { var eobj = new EventObj(); eobj._info = lst[i]; eobj._args = args; firedEvents.AddLast(eobj); } handles.UnLock(); }
private static bool _unregister(HandleTable handles, string eventname, object obj, string funcname) { handles.Lock(); List <Pair> lst; if (!handles.TryGetValue(eventname, out lst)) { handles.UnLock(); return(false); } for (int i = 0; i < lst.Count; i++) { if (obj == lst[i]._obj && lst[i]._funcname == funcname) { lst.RemoveAt(i); handles.UnLock(); return(true); } } handles.UnLock(); return(false); }
public static void _process(HandleTable handles) { handles.Lock(); if (handles._fired.Count > 0) { foreach (EventObj evt in handles._fired) { handles._doing.AddLast(evt); } handles._fired.Clear(); } handles.UnLock(); while (handles._doing.Count > 0) { EventObj eobj = handles._doing.First.Value; Debug.Log("process msg : " + eobj._info._funcname); try { eobj._info._method.Invoke(eobj._info._obj, eobj._args); } catch (Exception e) { Debug.Log("Event::processOutEvents: event=" + eobj._info._funcname + "\n" + e); } handles._doing.RemoveFirst(); } }
private static bool _hasRegister(HandleTable handles, string eventname) { bool has; handles.Lock(); has = handles.ContainsKey(eventname); handles.UnLock(); return(has); }
private static bool _register(HandleTable handles, string eventname, object obj, string funcname) { _unregister(handles, eventname, obj, funcname); List <Pair> lst; var pair = new Pair(); pair._obj = obj; pair._funcname = funcname; pair._method = obj.GetType().GetMethod(funcname); if (pair._method == null) { Debug.Log("funcname not exist: " + eventname + " " + funcname); return(false); } handles.Lock(); if (!handles.TryGetValue(eventname, out lst)) { lst = new List <Pair>(); lst.Add(pair); handles.Add(eventname, lst); handles.UnLock(); return(true); } lst.Add(pair); handles.UnLock(); return(true); }