/// <summary> /// 引发消息处理 /// </summary> /// <param name="inEvent">Evt.</param> public bool TriggerEvent(IGEvent inEvent) { List <GEventListenerWrapper> listenerList = null; if (mEventListenerMap.TryGetValue(inEvent.EventKey, out listenerList)) { for (int i = 0; i < listenerList.Count; i++) { GEventListenerWrapper wrapper = listenerList[i]; IGEventListener listener = wrapper.mEventListenerWeakRef.Target as IGEventListener; try { if (listener != null && listener.ListenerStatus != AttachableStatus.Detaching && listener.HandleEvent(inEvent)) { //说明这个监听器要求拦截消息,终止消息的继续广播// return(true); } } catch (Exception e) { Log.LMN.LogUtil.Error("MBLogicNode.TriggerEvent: listener -> {0}, excepton -> {1}", listener, e); } } } return(false); }
private bool OnNumAccumForDemo2(IGEvent inEvent) { bool ret = false; LMEvent_NumAccumForDemo2 realEvt = inEvent as LMEvent_NumAccumForDemo2; int newVal = realEvt.mNumberToAccum + 1; //注意这里异步发给了自己,下一帧就会收到// LMEvent_NumAccumForDemo2 anEvtToMyself = FakeObjPoolMgr.FetchAutoRecycleObj <LMEvent_NumAccumForDemo2>(); anEvtToMyself.mNumberToAccum = newVal; SendEventAsync(anEvtToMyself); //注意这里给M层也发了一份,那边是 DisplayUIForDemo2 等着收// if (X2MBridge.IsValid) { LMEvent_NumAccumForDemo2 anotherEvtToM = FakeObjPoolMgr.FetchAutoRecycleObj <LMEvent_NumAccumForDemo2>(); anotherEvtToM.mNumberToAccum = newVal; //注意这里发送给了M层// X2MBridge.Instance.SendEventAsync(anotherEvtToM); } return(ret); }
/// <summary> /// 发送同步消息,立即完成消息的执行 /// 不可以跨线程使用 /// </summary> /// <returns><c>true</c>, if event sync was sent, <c>false</c> otherwise.</returns> /// <param name="inEvt">In evt.</param> public virtual bool SendEventSync(IGEvent inEvt) { bool ret = false; if (inEvt == null) { return(ret); } if (NodeStatus != AttachableStatus.Attached) { //这种时候发送消息是不成功的,这个消息要准备被释放// if (inEvt.IsAutoRecycle) { inEvt.IsReadyToRecycle = true; } return(ret); } if (!IsNodeActive) { return(ret); } DispatchAnEvent(inEvt); TryToRecycleThisEvent(inEvt); ret = true; return(ret); }
/// <summary> /// 广播一个消息 /// </summary> /// <param name="inEvent">Evt.</param> public virtual bool DispatchAnEvent(IGEvent inEvent) { if (AsEventDispatcher) { if (TriggerEvent(inEvent)) { return(true); } for (int i = 0; i < mSubNodes.Count; i++) { GLogicNodeWrapper wrapper = mSubNodes[i]; if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching && wrapper.mLogicNode.IsNodeActive) { if (wrapper.mLogicNode.DispatchAnEvent(inEvent)) { //说明某个消息监听器要求拦截消息,终止了消息的继续广播// return(true); } } } } return(false); }
/// <summary> /// 尝试去释放一个消息 /// </summary> /// <param name="inEvent"></param> /// <returns></returns> public virtual void TryToRecycleThisEvent(IGEvent inEvent) { //如果是自动释放类消息,那这里标记它可以释放了// if (inEvent.IsAutoRecycle) { inEvent.IsReadyToRecycle = true; } }
/// <summary> /// 处理输入的消息 /// </summary> /// <param name="inEvent"></param> /// <returns> 如果希望阻止消息的继续派发,返回true </returns> public bool HandleEvent(IGEvent inEvent) { bool ret = false; // switch (inEvent.EventKey) // { // // } return(ret); }
/// <summary> /// 处理输入的消息 /// </summary> /// <param name="inEvent"></param> /// <returns> 如果希望阻止消息的继续派发,返回true </returns> public bool HandleEvent(IGEvent inEvent) { bool ret = false; switch (inEvent.EventKey) { case (int)eFakeEventIdDefs.ServerGoOneFrameForDemo3: { ret = OnServerGoOneFrameForDemo3(inEvent); } break; } return(ret); }
private bool OnShowDisplayUIForDemo2(IGEvent inEvent) { bool ret = false; GameObject ui = GameObject.Instantiate(Resources.Load("TextForDemo2")) as GameObject; GameObject canvas = GameObject.FindGameObjectWithTag("Demo2Canvas"); (ui.transform as RectTransform).SetParent(canvas.transform); return(ret); }
/// <summary> /// 处理输入的消息 /// </summary> /// <param name="inEvent"></param> /// <returns> 如果希望阻止消息的继续派发,返回true </returns> public bool HandleEvent(IGEvent inEvent) { bool ret = false; switch (inEvent.EventKey) { case (int)eFakeEventIdDefs.LogToUnity: { ret = OnLogToUnity(inEvent); } break; } return(ret); }
/// <summary> /// 处理输入的消息 /// </summary> /// <param name="inEvent"></param> /// <returns> 如果希望阻止消息的继续派发,返回true </returns> public bool HandleEvent(IGEvent inEvent) { bool ret = false; switch (inEvent.EventKey) { case (int)eFakeEventIdDefs.NumAccumForDemo2: { ret = OnNumAccumForDemo2(inEvent); } break; } return(ret); }
private bool OnServerGoOneFrameForDemo3(IGEvent inEvent) { bool ret = false; LMNEvent_ServerGoOneFrameForDemo3 realEvt = inEvent as LMNEvent_ServerGoOneFrameForDemo3; //这里模拟收到了服务器的帧驱动// //注意,如果你真的写好了多线程自动回收对象池的话,这个地方是不能直接缓存来自网络线程的对象的// mFakeFrameBuffer.Add(realEvt.mServerFrame, realEvt); return(ret); }
private bool OnNumAccumForDemo2(IGEvent inEvent) { bool ret = false; if (mDisplayText == null) { LogUtil.Error("DisplayUIForDemo2.OnNumAccumForDemo2: mDisplayText invalid"); return(ret); } LMEvent_NumAccumForDemo2 realEvt = inEvent as LMEvent_NumAccumForDemo2; mDisplayText.text = realEvt.mNumberToAccum.ToString(); return(ret); }
private bool OnLogToUnity(IGEvent inEvent) { bool ret = false; LMEvent_LogToUnity realEvt = inEvent as LMEvent_LogToUnity; switch (realEvt.mLogLevel) { case DemoLogLevel.Error: { UnityEngine.Debug.LogError(realEvt.mLogStr); } break; case DemoLogLevel.Warning: { UnityEngine.Debug.LogWarning(realEvt.mLogStr); } break; case DemoLogLevel.Debug: { UnityEngine.Debug.Log(realEvt.mLogStr); } break; } return(ret); }
private bool OnNumAccumForDemo1(IGEvent inEvent) { bool ret = false; LMEvent_NumAccumForDemo1 realEvt = inEvent as LMEvent_NumAccumForDemo1; if (X2LBridge.IsValid) { LMEvent_NumAccumForDemo1 evt = FakeObjPoolMgr.FetchAutoRecycleObj <LMEvent_NumAccumForDemo1>(); evt.mNumberToAccum = realEvt.mNumberToAccum + 1; //注意这里发送给了L层// X2LBridge.Instance.SendEventAsync(evt); LogUtil.Debug("MNumAccSys.OnNumAccum: MFrame {0}, from {1} to {2}", LMDataOcean.mMainThreadFrameCounter, realEvt.mNumberToAccum, evt.mNumberToAccum); } return(ret); }
/// <summary> /// 发送异步消息,会在下一帧执行 /// 在节点是线程安全节点的时候,可以跨线程使用 /// </summary> /// <returns><c>true</c>, if event async was sent, <c>false</c> otherwise.</returns> /// <param name="inEvt">In evt.</param> /// <param name="inCachUpWhenInactive">If set to <c>true</c> in cach up when inactive.</param> public virtual bool SendEventAsync(IGEvent inEvt, bool inCachUpWhenInactive = false) { bool ret = false; if (inEvt == null) { return(ret); } if (NodeStatus != AttachableStatus.Attached) { //这种时候发送消息是不成功的,这个消息要准备被释放// if (inEvt.IsAutoRecycle) { inEvt.IsReadyToRecycle = true; } return(ret); } if (!IsNodeActive && !inCachUpWhenInactive) { return(ret); } if (ThreadSafeLock != null) { lock (ThreadSafeLock) { mEventQueueForNextFrame.Add(inEvt); } } else { mEventQueueForNextFrame.Add(inEvt); } ret = true; return(ret); }
/// <summary> /// 广播消息 /// </summary> public virtual void DispatchEvents() { //先把在我身上抛的消息dispatch掉// for (int i = 0; i < mEventQueueForThisFrame.Count; i++) { IGEvent evt = mEventQueueForThisFrame[i]; DispatchAnEvent(evt); TryToRecycleThisEvent(evt); } mEventQueueForThisFrame.Clear(); if (AsEventDispatcher) { for (int i = 0; i < mSubNodes.Count; i++) { GLogicNodeWrapper wrapper = mSubNodes[i]; if (wrapper.mLogicNode.NodeStatus != AttachableStatus.Detaching && wrapper.mLogicNode.IsNodeActive) { wrapper.mLogicNode.DispatchEvents(); } } } }
/// <summary> /// 用于在Bridge上面需要发同步消息的情况 /// 注意必须是这个Bridge所在的线程才能来调用这个方法,不然就是多线程问题 /// /// 如果是网络请求,就自动把它变成自动释放的包 /// </summary> /// <param name="inEvt"></param> /// <returns></returns> public bool SendEventSyncOnlyWhenYouKnownWhatYouAreDoing(IGEvent inEvt) { return(base.SendEventSync(inEvt)); }
public override bool SendEventSync(IGEvent inEvt) { LogUtil.Error("X2NBridge.SendEventSync: don't Call this func, it's not safe"); return(false); }
/// <summary> /// 处理输入的消息 /// </summary> /// <param name="inEvent"></param> /// <returns> 如果希望阻止消息的继续派发,返回true </returns> public bool HandleEvent(IGEvent inEvent) { bool ret = false; return(ret); }