public IGLogicNode GetNodeByName(int inNodeName) { IGLogicNode ret = null; mNameAndNodeMap.TryGetValue(inNodeName, out ret); return(ret); }
private bool _AttachNodeAsync(IGLogicNode inLogicNode) { bool ret = false; if (inLogicNode == null) { Log.LMN.LogUtil.Error("MBLogicNode._AttachNodeAsync: inLogicNode is null"); return(ret); } //置脏,导致这棵子树需要进入更新流程// IsLogicTreeNeedsUpdate = true; IGLogicNode parent = ParentNode; while (parent != null && !parent.IsLogicTreeNeedsUpdate) { parent.IsLogicTreeNeedsUpdate = true; parent = parent.ParentNode; } LogicNodeUpdateOperation updateOp = new LogicNodeUpdateOperation(); updateOp.mIsAddOrRemove = true; updateOp.mLogicNode = inLogicNode; mAsyncNodeOps.Add(updateOp); ret = true; return(ret); }
private bool _DetachAllSubNodesAsync() { bool ret = false; for (int i = 0; i < mSubNodes.Count; i++) { GLogicNodeWrapper wrapper = mSubNodes[i]; wrapper.mLogicNode.NodeStatus = AttachableStatus.Detaching; } //置脏,导致这棵子树需要进入更新流程// IsLogicTreeNeedsUpdate = true; IGLogicNode parent = ParentNode; while (parent != null && !parent.IsLogicTreeNeedsUpdate) { parent.IsLogicTreeNeedsUpdate = true; parent = parent.ParentNode; } LogicNodeUpdateOperation updateOp = new LogicNodeUpdateOperation(); updateOp.mIsRemoveAll = true; updateOp.mIsAddOrRemove = false; mAsyncNodeOps.Add(updateOp); return(ret); }
private bool _AttachListenerAsync(int inEventKey, IGEventListener inListener) { bool ret = false; if (inListener == null) { Log.LMN.LogUtil.Error("MBLogicNode._AttachListenerAsync: inLogicNode is null"); return(ret); } //置脏,导致这棵子树需要进入更新流程// IsListenerTreeNeedsUpdate = true; IGLogicNode parent = ParentNode; while (parent != null && !parent.IsListenerTreeNeedsUpdate) { parent.IsListenerTreeNeedsUpdate = true; parent = parent.ParentNode; } EventListenerUpdateOperation updateOp = new EventListenerUpdateOperation(); updateOp.mListener = inListener; updateOp.mIsAddOrRemove = true; updateOp.mEventKey = inEventKey; mAsyncListenerOps.Add(updateOp); inListener.ListenerStatus = AttachableStatus.Attaching; ret = true; return(ret); }
/// <summary> /// 注意NLogicCore的这个方法平时没有用,在单线程模式下才有用 /// </summary> /// <param name="inLogicNode"></param> public override void OnAttached(IGLogicNode inLogicNode) { base.OnAttached(inLogicNode); OnStart(); InitSubNodes(); }
/// <summary> /// 注意NLogicCore的这个方法平时没有用,在单线程模式下才有用 /// </summary> /// <param name="inLogicNode"></param> public override void OnDetached(IGLogicNode inLogicNode) { base.OnDetached(inLogicNode); OnStop(); ShutdownSubNodes(); }
public override void OnDetached(IGLogicNode inLogicNode) { base.OnDetached(inLogicNode); if (X2MBridge.IsValid) { X2MBridge.Instance.DetachListener((int)eFakeEventIdDefs.LogToUnity, this); } }
public override void OnDetached(IGLogicNode inLogicNode) { base.OnDetached(inLogicNode); if (X2LBridge.IsValid) { X2LBridge.Instance.DetachListener((int)eFakeEventIdDefs.ServerGoOneFrameForDemo3, this); } }
public override void OnDetached(IGLogicNode inLogicNode) { base.OnDetached(inLogicNode); if (X2MBridge.IsValid) { X2MBridge.Instance.DetachListener((int)eFakeEventIdDefs.NumAccumForDemo1, this); X2MBridge.Instance.DetachListener((int)eFakeEventIdDefs.ShowDisplayUIForDemo2, this); } }
private bool _DetachListenerAsync(int inEventKey, IGEventListener inListener) { bool ret = false; if (inListener == null) { Log.LMN.LogUtil.Error("MBLogicNode._DetachListenerAsync: inLogicNode is null"); return(ret); } //置脏,导致这棵子树需要进入更新流程// IsListenerTreeNeedsUpdate = true; IGLogicNode parent = ParentNode; while (parent != null && !parent.IsListenerTreeNeedsUpdate) { parent.IsListenerTreeNeedsUpdate = true; parent = parent.ParentNode; } List <GEventListenerWrapper> listenerWrappers = null; if (!mEventListenerMap.TryGetValue(inEventKey, out listenerWrappers)) { Log.LMN.LogUtil.Error("MBLogicNode._DetachListenerAsync: no event listener for -> {0} on {1}", inEventKey, inListener); return(ret); } //快速找出需要移除的节点位置// int priority = inListener.GetPriority(inEventKey); int index = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GEventListenerWrapper>(priority, listenerWrappers); for (int i = index; i < listenerWrappers.Count && listenerWrappers[i].PriorityVal == priority; i++) { GEventListenerWrapper wrapper = listenerWrappers[i]; object listenerObj = wrapper.mEventListenerWeakRef.Target; if (listenerObj == inListener) { inListener.ListenerStatus = AttachableStatus.Detaching; ret = true; break; } } if (ret) { EventListenerUpdateOperation updateOp = new EventListenerUpdateOperation(); updateOp.mListener = inListener; updateOp.mIsAddOrRemove = false; updateOp.mEventKey = inEventKey; mAsyncListenerOps.Add(updateOp); } return(ret); }
private bool _AttachNodeSync(IGLogicNode inLogicNode) { bool ret = false; if (inLogicNode == null) { //请替换成你的log函数// Log.LMN.LogUtil.Error("ObjLogicNode._AttachNodeSync: inLogicNode is null"); return(ret); } #if DEBUG_G_LOGIC_NODE bool foundDuplicate = false; for (int i = 0; i < mSubNodes.Count; i++) { GLogicNodeWrapper wrapper = mSubNodes[i]; if (wrapper.mLogicNode == inLogicNode) { foundDuplicate = true; break; } } //请替换成你的log函数// System.Diagnostics.Debug.Assert(!foundDuplicate, "ObjLogicNode._AttachNodeSync: found duplicated LogicNode -> " + inLogicNode); #endif GLogicNodeWrapper newLogicNodeWrapper = new GLogicNodeWrapper(); newLogicNodeWrapper.mLogicNode = inLogicNode; newLogicNodeWrapper.mLogicNode.NodeStatus = AttachableStatus.Attached; //找出插入位置// int index = PrioritySortUtil.GetDecSeqRefArrayInsertIndex <GLogicNodeWrapper>(inLogicNode.LogicNodePriority, mSubNodes); mSubNodes.Insert(index, newLogicNodeWrapper); //赋值父节点// inLogicNode.ParentNode = this; //如果节点有名字,那注册名字// if (inLogicNode.NodeName != 0) { mNameAndNodeMap.Add(inLogicNode.NodeName, inLogicNode); } inLogicNode.OnAttached(this); ret = true; return(ret); }
public override void OnAttached(IGLogicNode inLogicNode) { base.OnAttached(inLogicNode); if (X2LBridge.IsValid) { X2LBridge.Instance.AttachListener((int)eFakeEventIdDefs.NumAccumForDemo1, this); //EntranceForDemo2 第一次从这里收到// X2LBridge.Instance.AttachListener((int)eFakeEventIdDefs.NumAccumForDemo2, this); } //之后是自己发给自己的// AttachListener((int)eFakeEventIdDefs.NumAccumForDemo2, this); }
/// <summary> /// 在将要从逻辑树摘除时回调,OnDetached 之前 /// </summary> /// <param name="inLogicNode"></param> public virtual void OnPreDetach(IGLogicNode inLogicNode) { //这里清空没有来得及发出去的消息// if (ThreadSafeLock != null) { lock (ThreadSafeLock) { foreach (IGEvent evt in mEventQueueFrameOdd) { if (evt.IsAutoRecycle) { evt.IsReadyToRecycle = true; } } mEventQueueFrameOdd.Clear(); foreach (IGEvent evt in mEventQueueFrameEven) { if (evt.IsAutoRecycle) { evt.IsReadyToRecycle = true; } } mEventQueueFrameEven.Clear(); } } else { foreach (IGEvent evt in mEventQueueFrameOdd) { if (evt.IsAutoRecycle) { evt.IsReadyToRecycle = true; } } mEventQueueFrameOdd.Clear(); foreach (IGEvent evt in mEventQueueFrameEven) { if (evt.IsAutoRecycle) { evt.IsReadyToRecycle = true; } } mEventQueueFrameEven.Clear(); } }
private bool _DetachNodeSync(IGLogicNode inLogicNode) { bool ret = false; if (inLogicNode == null) { //请替换成你的log函数// Log.LMN.LogUtil.Error("ObjLogicNode._DetachNodeSync: inLogicNode is null"); return(ret); } //快速找出节点位置// int index = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GLogicNodeWrapper>(inLogicNode.LogicNodePriority, mSubNodes); int indexToRemove = -1; for (int i = index; i < mSubNodes.Count && mSubNodes[i].PriorityVal == inLogicNode.LogicNodePriority; i++) { GLogicNodeWrapper wrapper = mSubNodes[i]; if (wrapper.mLogicNode == inLogicNode) { indexToRemove = i; break; } } if (indexToRemove != -1) { mSubNodes.RemoveAt(indexToRemove); //如果节点有名字,那注销// if (inLogicNode.NodeName != 0) { mNameAndNodeMap.Remove(inLogicNode.NodeName); } inLogicNode.NodeStatus = AttachableStatus.Detached; inLogicNode.OnPreDetach(this); inLogicNode.OnDetached(this); inLogicNode.ParentNode = null; ret = true; } return(ret); }
private bool _DetachNodeAsync(IGLogicNode inLogicNode) { bool ret = false; if (inLogicNode == null) { //请替换成你的log函数// Log.LMN.LogUtil.Error("ObjLogicNode._DetachNodeAsync: inLogicNode is null"); return(ret); } //快速找出节点位置// int index = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GLogicNodeWrapper>(inLogicNode.LogicNodePriority, mSubNodes); for (int i = index; i < mSubNodes.Count && mSubNodes[i].PriorityVal == inLogicNode.LogicNodePriority; i++) { GLogicNodeWrapper wrapper = mSubNodes[i]; if (wrapper.mLogicNode == inLogicNode) { wrapper.mLogicNode.NodeStatus = AttachableStatus.Detaching; break; } } //置脏,导致这棵子树需要进入更新流程// IsLogicTreeNeedsUpdate = true; IGLogicNode parent = ParentNode; while (parent != null && !parent.IsLogicTreeNeedsUpdate) { parent.IsLogicTreeNeedsUpdate = true; parent = parent.ParentNode; } LogicNodeUpdateOperation updateOp = new LogicNodeUpdateOperation(); updateOp.mIsAddOrRemove = false; updateOp.mLogicNode = inLogicNode; mAsyncNodeOps.Add(updateOp); ret = true; return(ret); }
/// <summary> /// 1.将一个逻辑节点从我身上摘除 /// 2.非线程安全 /// 3.在 OnAttached/OnDetached/OnUpdate 这几个API中调用的时候会形成异步命令, 参见IsNodeTreeLocked /// 4.在调用后该节点会立即停止工作,参见 mIsAttachedLogically /// </summary> /// <param name="inLogicNode"></param> /// <returns></returns> public bool DetachNode(IGLogicNode inLogicNode) { bool ret = false; if (inLogicNode == null) { Log.LMN.LogUtil.Error("MBLogicNode.DetachNode: inLogicNode is null"); return(ret); } if (IsNodeTreeLocked) { ret = _DetachNodeAsync(inLogicNode); } else { ret = _DetachNodeSync(inLogicNode); } return(ret); }
/// <summary> /// 1.将一个LogicNode挂到我身上 /// 2.非线程安全 /// 3.在 OnAttached/OnDetached/OnUpdate 这几个API中调用的时候会形成异步命令, 参见IsNodeTreeLocked /// </summary> /// <param name="inLogicNode"></param> /// <returns></returns> public bool AttachNode(IGLogicNode inLogicNode) { bool ret = false; if (inLogicNode == null) { //请替换成你的log函数// Log.LMN.LogUtil.Error("ObjLogicNode.AttachNode: inLogicNode is null"); return(ret); } if (IsNodeTreeLocked) { ret = _AttachNodeAsync(inLogicNode); } else { ret = _AttachNodeSync(inLogicNode); } return(ret); }
/// <summary> /// 在从逻辑树摘除的时候进行回调 /// </summary> /// <param name="inLogicNode"></param> public virtual void OnDetached(IGLogicNode inLogicNode) { }