public void TriggerEvent <U, V, W>(string ge, U arg1, V arg2, W arg3) { EventNode[] tpList = PrepareNodeList(ge); if (tpList != null) { foreach (EventNode node in tpList) { EventFunction <U, V, W> ef = node.function as EventFunction <U, V, W>; if (ef != null) { ef(ge, arg1, arg2, arg3); } //else //AiToyDebug.LogError(string.Format("处理事件 \"{0}\" 时回调函数参数不匹配", ge) ); } } try { // if (LuaMgr.instance.TriggerEvent() != null) // { // LuaMgr.instance.TriggerEvent().Action<string, U, V, W>(ge, arg1, arg2, arg3); // } } catch (System.Exception ex) { LogMgr.instance.Log(LogLevel.ERROR, LogTag.Lua, "lua exception:" + ex.Message + " stack:" + ex.StackTrace); } }
// If the afterFinishedSend flag is true, the event will be unregistered after send is complete // for all events. This is slow and should be avoided. Unregister events outside the function they // are registered with, to avoid this. public void UnRegister <T>(EventFunction <T> subscribingFunction, bool afterFinishedSend = false) { if (!m_events.ContainsKey(typeof(T))) { return; } for (int i = 0; i < m_events[typeof(T)].Count; ++i) { if (m_events[typeof(T)][i] == subscribingFunction as Delegate) { if (afterFinishedSend) { if (!m_eventsToUnRegister.ContainsKey(typeof(T))) { m_eventsToUnRegister.Add(typeof(T), new List <Delegate>()); } m_eventsToUnRegister[typeof(T)].Add(subscribingFunction); return; } m_events[typeof(T)].RemoveAt(i); if (m_events[typeof(T)].Count == 0) { m_events.Remove(typeof(T)); } return; } } }
public void ExecuteEvent <T>(EventFunction <T> functor) where T : IEventSystemHandler { foreach (GameObject gameObject in _listeners) { Execute(gameObject, null, functor); } }
public static void Execute <THandler>(GameObject gameObject, EventFunction <THandler> function, INavigationParameters navigationParameters) where THandler : class, INavigationEventHandler { if (gameObject == null) { throw new ArgumentNullException(nameof(gameObject)); } if (function == null) { throw new ArgumentNullException(nameof(function)); } GetHandlersFromGameObject(gameObject, s_NavigationEventHandlers); int count = s_NavigationEventHandlers.Count; for (int i = 0; i < count; i++) { var handler = s_NavigationEventHandlers[i] as THandler; if (handler != null) { function(handler, navigationParameters); } } }
public void TriggerEvent(string ge) { EventNode[] tpList = PrepareNodeList(ge); if (tpList == null) { return; } foreach (EventNode node in tpList) { EventFunction ef = node.function as EventFunction; EventFunc ef1 = node.function as EventFunc; if (ef != null) { ef(ge); } else if (ef1 != null) { ef1(); } else { Debug.LogError(string.Format("处理事件 \"{0}\" 时回调函数参数不匹配", ge)); } } }
public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler { List <IEventSystemHandler> list = s_HandlerListPool.Get(); GetEventList <T>(target, list); for (int i = 0; i < list.Count; i++) { T handler; try { handler = (T)list[i]; } catch (Exception innerException) { IEventSystemHandler eventSystemHandler = list[i]; Debug.LogException(new Exception($"Type {typeof(T).Name} expected {eventSystemHandler.GetType().Name} received.", innerException)); continue; } try { functor(handler, eventData); } catch (Exception exception) { Debug.LogException(exception); } } int count = list.Count; s_HandlerListPool.Release(list); return(count > 0); }
private void SafeInvoke(int eventId, bool isImmediately, IUserData userData) { EventFunction listener = m_Listeners[eventId]; if (listener == null) { MDebug.LogVerbose("EventCenter", $"Event ({m_EventIdToName[eventId]}) not have listener."); if (userData is IObjectPoolItem poolItem) { Kernel.ObjectPool.Release(poolItem); } return; } try { MDebug.LogVerbose("EventCenter" , $"Event ({m_EventIdToName[eventId]}) begin invoke."); listener.Invoke(eventId, isImmediately, userData); if (userData is IObjectPoolItem poolItem) { Kernel.ObjectPool.Release(poolItem); } MDebug.LogVerbose("EventCenter" , $"Event ({m_EventIdToName[eventId]}) end invoke."); } catch (Exception e) { MDebug.LogError("EventCenter" , $"Event ({m_EventIdToName[eventId]}) invoke Exception:\n{e.ToString()}"); } }
public EventStreamEmitter(ConcurrentQueue<String> _queue, EventFunction _raiseEvent, AutoResetEvent _emitterWaitHandle, string _eventName = null, bool _exactMatch = false) { queue = _queue; filterEventName = _eventName; emitterWaitHandle = _emitterWaitHandle; exactMatch = _exactMatch; raiseEvent = _raiseEvent; }
public EventStreamEmitter(ConcurrentQueue <String> _queue, EventFunction _raiseEvent, AutoResetEvent _emitterWaitHandle, string _eventName = null, bool _exactMatch = false) { queue = _queue; filterEventName = _eventName; emitterWaitHandle = _emitterWaitHandle; exactMatch = _exactMatch; raiseEvent = _raiseEvent; }
public EventTimerInst(EventTimer timer, EventFunction eventFunc, CharacterPawn pawn, ActorInstance.ActorBase actor) { this.timer = timer; this.funcToExecute = eventFunc; this.pawn = pawn; this.actor = actor; timer.Init(this); }
public void Register <T>(EventFunction <T> subscribingFunction) { if (!m_events.ContainsKey(typeof(T))) { m_events.Add(typeof(T), new List <Delegate>()); } m_events[typeof(T)].Add(subscribingFunction); }
public bool IsContain(EventFunction func) { if (func == null) { return(false); } return(m_EventList.IndexOf(func) >= 0); }
// EventTypeとコンストラクタで渡されたイベントの型が一致していればfuncを実行(EventType変数の引数無しver) public virtual bool Dispatch <EventType>(EventFunction func) where EventType : EventBase { if (m_Event.GetType() == typeof(EventType)) { func(); return(true); } return(false); }
public Event(GameObject gameObject_, int duration_, EventFunction eventFunction_, bool recurrent_ = false, int variance_ = 0) { tick = S_World.tick; duration = duration_; variance = variance_; activate_tick = tick + duration_ + (int)(variance * Random.value); eventFunction = eventFunction_; gameObject = gameObject_; recurrent = recurrent_; }
private void ExecuteEvent <T>(EventFunction <T> func, object arg, bool includeDisabled = false) where T : IControllerEventHandler { for (int i = 0; i < this.m_ControllerEvents.Length; i++) { IControllerEventHandler handler = this.m_ControllerEvents[i]; if (ShouldSendEvent <T>(handler, includeDisabled)) { func.Invoke((T)handler, arg); } } }
/// <summary> /// Execute the specified functions. /// </summary> public void Execute <T>(EventFunction <T> functor) where T : class { foreach (var obj in mListObject) { var listener = obj as T; if (listener != null) { functor.Invoke(listener); } } }
public void Remove(EventFunction func) { int idx = m_EventList.IndexOf(func); if (idx == -1) { return; } m_EventList.RemoveAt(idx); m_TriggerCount++; }
public Combination(List <Keys> combinaison, EventFunction f) { _f = f; _combinaison = combinaison; foreach (Keys k in _combinaison) { _gkh.HookedKeys.Add(k); _pressed.Add(false); } _gkh.KeyDown += new KeyEventHandler(gkh_KeyDown); _gkh.KeyUp += new KeyEventHandler(gkh_KeyUp); }
public void MoveDecorationsTo(EventFunction func) { if (Decorations != null) { if (func.EndComments == null) { func.EndComments = new List <SourceDecoration>(); } func.EndComments.AddRange(Decorations); Decorations = null; } }
public static void Unregister(EventbusEvent eventType, EventFunction function) { List <EventFunction> eventFunctions; EventListener.TryGetValue(eventType, out eventFunctions); if (eventFunctions == null) { return; } eventFunctions.Remove(function); }
public static void Register(EventbusEvent eventType, EventFunction function) { List <EventFunction> eventFunctions; EventListener.TryGetValue(eventType, out eventFunctions); if (eventFunctions == null) { eventFunctions = new List <EventFunction>(); EventListener.Add(eventType, eventFunctions); } eventFunctions.Add(function); }
public static GameObject ExecuteHierarchy <T>(GameObject root, BaseEventData eventData, EventFunction <T> callbackFunction) where T : IEventSystemHandler { GetEventChain(root, s_InternalTransformList); for (var i = 0; i < s_InternalTransformList.Count; i++) { var transform = s_InternalTransformList[i]; if (Execute(transform.gameObject, eventData, callbackFunction)) { return(transform.gameObject); } } return(null); }
//private static readonly ObjectPool<List<IEventSystemHandler>> s_HandlerListPool = new ObjectPool<List<IEventSystemHandler>>(null, l => l.Clear()); public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler { if (target == null) { return(false); } bool executed = false; foreach (Component component in target.GetComponents <Component>()) { if (ShouldSendToComponent <T>(component)) { functor((T)(component as IEventSystemHandler), eventData); executed = true; } } return(executed); //var internalHandlers = s_HandlerListPool.Get(); //GetEventList<T>(target, internalHandlers); // if (s_InternalHandlers.Count > 0) // Debug.Log("Executinng " + typeof (T) + " on " + target); //for (var i = 0; i < internalHandlers.Count; i++) { // T arg; // try { // arg = (T) internalHandlers[i]; // } catch (Exception e) { // var temp = internalHandlers[i]; // Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, temp.GetType().Name), e)); // continue; // } // try { // functor(arg, eventData); // } catch (Exception e) { // Debug.LogException(e); // } //} //var handlerCount = internalHandlers.Count; //s_HandlerListPool.Release(internalHandlers); //return handlerCount > 0; }
/// <summary> /// 这个就是ExecuteEvents.Execute(...)了,也是一个泛型方法,注意第三个参数functor就是之前的对应私有委托对象的公有属性。 /// 对应到PointerEnter类型之后就是下边这个样子: /// ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); /// /// 获取target所有可以响应该事件的组件component存入internalHandlers,然后执行它们的回调方法。 /// 最后返回一个bool值internalHandlers是否为空,即是否有组件可以响应(响应了)这次调用要执行的事件。 /// </summary> /// <param name="target"></param> /// <param name="eventData"></param> /// <param name="functor"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler { var internalHandlers = s_HandlerListPool.Get(); //找到target身上所有实现了IEventSystemHandler接口的组件 //且该组件处于激活状态且可用 GetEventList <T>(target, internalHandlers); // if (s_InternalHandlers.Count > 0) // Debug.Log("Executinng " + typeof (T) + " on " + target); //依次向这些T类型组件发送T类型的事件 for (var i = 0; i < internalHandlers.Count; i++) { T arg; try { arg = (T)internalHandlers[i]; } catch (Exception e) { var temp = internalHandlers[i]; Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, temp.GetType().Name), e)); continue; } try { functor(arg, eventData); } catch (Exception e) { Debug.LogException(e); } } var handlerCount = internalHandlers.Count; s_HandlerListPool.Release(internalHandlers); //返回该事件是否被消费 return(handlerCount > 0); }
public void TriggerEvent <U, V, W, M>(string ge, U arg1, V arg2, W arg3, M arg4) { EventNode[] tpList = PrepareNodeList(ge); if (tpList == null) { return; } foreach (EventNode node in tpList) { EventFunction <U, V, W, M> ef = node.function as EventFunction <U, V, W, M>; if (ef != null) { ef(ge, arg1, arg2, arg3, arg4); } else { Debug.LogError(string.Format("处理事件 \"{0}\" 时回调函数参数不匹配", ge)); } } }
//Execute event protected void ExecuteEvent <T>(EventFunction <T> func, bool includeDisabled = false) where T : ITriggerEventHandler { for (int i = 0; i < this.m_TriggerEvents.Length; i++) { ITriggerEventHandler handler = this.m_TriggerEvents[i]; if (ShouldSendEvent <T>(handler, includeDisabled)) { func.Invoke((T)handler, PlayerInfo.gameObject); } } string eventID = string.Empty; if (this.m_CallbackHandlers.TryGetValue(typeof(T), out eventID)) { CallbackEventData triggerEventData = new CallbackEventData(); triggerEventData.AddData("Trigger", this); triggerEventData.AddData("Player", PlayerInfo.gameObject); triggerEventData.AddData("EventData", new PointerEventData(EventSystem.current)); base.Execute(eventID, triggerEventData); } }
public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler { var internalHandlers = ListPool <IEventSystemHandler> .Get(); GetEventList <T>(target, internalHandlers); // if (s_InternalHandlers.Count > 0) // Debug.Log("Executinng " + typeof (T) + " on " + target); var internalHandlersCount = internalHandlers.Count; for (var i = 0; i < internalHandlersCount; i++) { T arg; try { arg = (T)internalHandlers[i]; } catch (Exception e) { var temp = internalHandlers[i]; Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, temp.GetType().Name), e)); continue; } try { functor(arg, eventData); } catch (Exception e) { Debug.LogException(e); } } var handlerCount = internalHandlers.Count; ListPool <IEventSystemHandler> .Release(internalHandlers); return(handlerCount > 0); }
public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler { var internalHandlers = s_HandlerListPool.Get(); GetEventList <T>(target, internalHandlers); for (int i = 0; i < internalHandlers.Count; i++) { T arg; try { arg = (T)internalHandlers[i]; } catch (Exception e) { var temp = internalHandlers[i]; Debug.LogException(new Exception(string.Format("Type {0} expected, {1} received", typeof(T).Name, temp.GetType().Name), e)); continue; } try { functor(arg, eventData); } catch (Exception e) { Console.WriteLine(e); throw; } } var handlerCount = internalHandlers.Count; s_HandlerListPool.Release(internalHandlers); //NOTE, 只要有处理handler 就返回true return(handlerCount > 0); }
//通过GetEventChain获取target的所有父对象,并对这些对象(包括target)执行Execute方法 public static GameObject ExecuteHierarchy <T>(GameObject root, BaseEventData eventData, EventFunction <T> callbackFunction) where T : IEventSystemHandler { GetEventChain(root, s_InternalTransformList);//理解:点击了子节点,也意味着,点击了父节点 for (var i = 0; i < s_InternalTransformList.Count; i++) { var transform = s_InternalTransformList[i]; //如果“事件执行链”中,执行返回true,则结束传播,并返回结束传播的对象 if (Execute(transform.gameObject, eventData, callbackFunction)) { return(transform.gameObject); } } return(null); }
public void OnEvent(string state, string eventName, EventFunction fn) { state = state.Trim(); eventName = eventName.Trim(); Events.Add(new EventInfo() { s = state, e = eventName, fn = fn }); }
public void Remove(EventFunction functor) { this.functor -= functor; }
public void OnAnyEvent(string eventName, EventFunction fn) { OnEvent("*", eventName, fn); }
public void Add(EventFunction func) { m_EventList.Add(func); m_TriggerCount++; }
public void SetEventClosed(EventFunction o) { m_EvtClosed = o; }
public void OnEvent(string pattern, EventFunction fn) { OnEvent(pattern.Split(','), fn); }
public void OnEvent(string[] eventInfos, EventFunction fn) { foreach(var eventInfo in eventInfos) { var rule = eventInfo.Split('.'); if (rule.Length != 2) { return; } OnEvent(rule[0], rule[1], fn); } }
public void Accept(EventFunction functor) { this.functor += functor; }
}//Event() //TODO not sure if we need this!! // // /// <summary> // /// Register a funtion handler to an event. // /// </summary> // public void RegisterEvent(string eventType) // { // //TODO add funct to dict if eventType exist. // // // int id = eventType.GetHashCode(); // //EventFunction fn = null; // eventList.Add(id, null); // } /// <summary> /// Register a funtion handler to an event. /// </summary> public void RegisterEventHandler(string eventType, EventFunction func, GameObject handler = null) { //TODO add funct to dict if eventType exist. int id = eventType.GetHashCode(); if(eventList.ContainsKey(id)) { Log.Debug("RegisterEventHandler as existing:"+ eventType); List<EventObject> eList = eventList[id]; eList.Add(new EventObject(handler, func)); // eList[id] = new EventObject(handler, func); } else { Log.Debug("RegisterEventHandler as new:"+ eventType); //add to list List<EventObject> eList = new List<EventObject>(); eList.Add(new EventObject(handler, func)); eventList.Add(id, eList); } }
public void RemoveEventHandler(string eventType, EventFunction func) { Log.Debug("RemoveEventHandler:"+ eventType); int id = eventType.GetHashCode(); if(eventList.ContainsKey(id)) { List<EventObject> eList = eventList[id]; foreach(EventObject e in eList) { if(e.function == func) { //Log.Debug("REMOVED EVENT"); //TODO might need another dropList here eList.Remove(e); return; } } } }
public EventObject(GameObject obj, EventFunction fn, string t = "") { gameObject = obj; function = fn; type = t; }