public static void Invoke(EventFunc dele) { ThreadEvent e = new ThreadEvent(dele); e.handle = GCHandle.Alloc(e); // we don't want the GC to collect the event too early PostEvent(qApp.receiver, e); }
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 void RemoveEventListner(string id, EventFunc func) { if (listeners.ContainsKey(id) && listeners[id] != null) { listeners [id] -= func; } }
/// <summary> /// Non-chainable counterpart to Send, returning the first response from a given target, interface and Functor. /// Eg.: var curState = EzMsg.Request<IFSM, FSMState>(gameObject, (x,y) => x.GetCurrentState()); /// </summary> /// <param name="target">Target GameObject</param> /// <param name="functor">Method to call, must return a T2 type</param> /// <param name="requestToChildren">Should the request be sent to children of target?</param> /// <param name="responseCheck">Should each request check for a non-null response? Use nullable types with this.</param> /// <typeparam name="T1">Required interface which should be implemented in a matching component</typeparam> /// <typeparam name="T2">Required method return type</typeparam> /// <returns>Response to Request, T2 type</returns> public static T2 Request <T1, T2>(GameObject target, EventFunc <T1, T2> functor, bool requestToChildren = true) where T1 : IEventSystemHandler { var response = Request(target, null, functor); if (!IsGenericNull(response) || target.transform.childCount == 0 || !requestToChildren) { return(response); } // GetComponentsInChildren(false) = exclude inactive for (var i = 0; i < target.GetComponentsInChildren <Transform>(false).Length; i++) { Transform child = target.GetComponentsInChildren <Transform>(false)[i]; // Skips `target` so it isn't requested twice if (child == target.transform) { continue; } response = Request(child.gameObject, null, functor); if (!IsGenericNull(response)) { return(response); } } return(response); }
public Listener GenListener(EventFunc action, int weight, bool isFilter) { Listener listener = new Listener(); listener.mAction = action; listener.mWeight = weight; listener.mIsFilter = isFilter; return(listener); }
/// <summary> /// 添加新事件 /// </summary> public void AddWork(EventFunc Func, object[] data) { RECORD aObj = new RECORD() { Func = Func, data = data }; m_Queue.Enqueue(aObj); }
//注销消息 public static void RemoveEvent(string eventID, EventFunc func) { if (_messageHanlde.ContainsKey(eventID)) { _messageHanlde[eventID] -= func; if (null == _messageHanlde[eventID]) { _messageHanlde.Remove(eventID); } } }
public void AddEventListener(string id, EventFunc func) { if (!listeners.ContainsKey(id)) { listeners [id] = func; } else { listeners [id] += func; } }
public static void AddEventListener(Events e, EventFunc func) { if (!_container.ContainsKey(e)) { _container.Add(e, func); } else { _container[e] += func; } }
//注册消息 public static void RegisterEvent(string eventID, EventFunc func) { if (_messageHanlde.ContainsKey(eventID)) { _messageHanlde[eventID] -= func; _messageHanlde[eventID] += func; } else { _messageHanlde.Add(eventID, func); } }
/// <summary> /// 添加新事件 /// </summary> public void AddWork(EventFunc Func, object[] data) { WorkItem aObj = new WorkItem() { Func = Func, data = data }; lock (m_Lock) { m_Sema.Release(); m_Queue.Enqueue(aObj); } }
/// <summary> /// 添加新事件 /// </summary> public void AddWork(EventFunc Func, object[] data) { WorkItem aObj = new WorkItem() { Func = Func, data = data, Sema = new Semaphore(0, 1) }; lock (m_Lock) { m_Sema.Release(); m_Queue.Enqueue(aObj); if (m_EnableWaitAll) { m_AllTasks.Add(aObj); } } }
public static void AddEvent(string eventname, object obj, string funcname) { RemoveEvent(eventname, obj, funcname); List <EventFunc> lst = null; EventFunc pair = new EventFunc(); pair.obj = obj; pair.funcname = funcname; pair.method = obj.GetType().GetMethod(funcname); if (events.TryGetValue(eventname, out lst)) { lst.Add(pair); } else { lst = new List <EventFunc>(); lst.Add(pair); events.Add(eventname, lst); } }
public static void DispatchEvent(string eventname, params object[] args) { List <EventFunc> list = null; if (events.TryGetValue(eventname, out list)) { for (int i = 0; i < list.Count;) { EventFunc func = list[i]; list[i].method.Invoke(list[i].obj, args); if (i >= list.Count) { break; } if (list[i] != func) { continue; } ++i; } } }
public static void RegisterUIEvent <T1, T2>(string eventName, EventFunc <T1, T2> func) { if (null == _uiEventTable) { _uiEventTable = new Dictionary <int, DelegateList>(); } int eventHash = eventName.GetHashCode(); // 이벤트가 아얘 없었으면 새로 할당해주어야 한다. if (false == _uiEventTable.ContainsKey(eventHash)) { DelegateList list = new DelegateList(); list.AddFunction <EventFunc <T1, T2> >(func); _uiEventTable.Add(eventHash, list); } else { // 이벤트에 함수 추가. _uiEventTable[eventHash].AddFunction <EventFunc <T1, T2> >(func); } }
public ThreadEvent(EventFunc d) : base(QEvent.TypeOf.User) { dele = d; GC.SuppressFinalize(this); // once the event has entered the event loop, Qt will care for it }
public ThreadEvent(EventFunc d) : base(QEvent.Type.User) { dele = d; GC.SuppressFinalize(this); // once the event has entered the event loop, Qt will care for it }
public void addEndEvent(Event.EventFunc endEvent) { this.onEnd = endEvent; }
public void addClickEvent(Event.EventFunc clickEvent) { this.onClick = clickEvent; }
public void func_insert(EventFunc func, int insert_num) { funcs_.Insert(insert_num, func); }
public void func_add(EventFunc func) { funcs_.Add(func); }
public Listener Register(string eventName, EventFunc action, int weight = 1000, bool isFilter = false) { return(Register(eventName, GenListener(action, weight, isFilter))); }
internal void Connect(string evt,EventFunc func) { object_addhandler(m_handle, evt, Marshal.GetFunctionPointerForDelegate (func) ); }
/// <summary> /// A Request sends a message asking for the second parameter type as return. Instead of a success/failure bool /// For primitives you must use, eg. bool? or int? in the method call to get `null as return, if no answer found /// </summary> /// <param name="target">Target GameObject to send the request</param> /// <param name="eventData">Event Data</param> /// <param name="functor">Actual Method to be executed</param> /// <typeparam name="T1">Functor type</typeparam> /// <typeparam name="T2">Return Type</typeparam> /// <returns></returns> public static T2 Request <T1, T2>(GameObject target, BaseEventData eventData, EventFunc <T1, T2> functor) where T1 : IEventSystemHandler { var internalHandlers = s_HandlerListPool.Get(); GetEventList <T1>(target, internalHandlers); // Debug Purposes Only // Debug.Log(internalHandlers.Count + " scripts found of type " + typeof (T1) + " on " + target.name); // // if (internalHandlers.Count > 0) // Debug.Log("Executing " + typeof (T1) + " on " + target); T2 returnValue = default(T2); for (var i = 0; i < internalHandlers.Count; i++) { T1 arg; try { arg = (T1)internalHandlers[i]; } catch (Exception e) { var temp = internalHandlers[i]; Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T1).Name, temp.GetType().Name), e)); continue; } try { if (arg == null || functor == null) { Debug.LogError("EzMsg: Incompatible Signature Type or Functor not assigned"); return(returnValue); } returnValue = functor(arg); } catch (Exception e) { Debug.LogException(e); } } return(returnValue); }
public Event(float time, EventFunc func) { this.time = time; this.func = func; }
public void AddListener(string ge, EventFunc ef, bool removeOnLoadScene = true, EventPriority priority = EventPriority.Medium) { AddListenerInternal(ge, ef, removeOnLoadScene, priority); }
private void Set <TInput, TResult>(Func <TInput, TResult> func, [CallerMemberName] string name = null) { _handlers[name] = new EventFunc <TInput, TResult>(func); }
public ThreadEvent(EventFunc d) : base(QEvent.TypeOf.User) { dele = d; }