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); }
private bool _AttachListenerSync(int inEventKey, IGEventListener inListener) { bool ret = false; if (inListener == null) { //请替换成你的log函数// Log.LMN.LogUtil.Error("ObjLogicNode._AttachListenerSync: inLogicNode is null"); return(ret); } List <GEventListenerWrapper> eventListenerList = null; if (!mEventListenerMap.TryGetValue(inEventKey, out eventListenerList)) { eventListenerList = new List <GEventListenerWrapper>(); mEventListenerMap.Add(inEventKey, eventListenerList); } #if DEBUG_G_LOGIC_NODE for (int i = 0; i < eventListenerList.Count; i++) { GEventListenerWrapper wrapper = eventListenerList[i]; if (wrapper.mEventListenerWeakRef.IsAlive && wrapper.mEventListenerWeakRef.Target == inListener) { //请替换成你的log函数// Log.LMN.LogUtil.Error("ObjLogicNode._AttachListenerSync: duplicated -> " + inListener + ", in -> " + this + ", for -> " + inEventKey); return(ret); } } #endif int priority = inListener.GetPriority(inEventKey); GEventListenerWrapper listenerWrapper; listenerWrapper.mEventListenerWeakRef = new WeakReference(inListener); listenerWrapper.mEventListenerPriority = priority; inListener.ListenerStatus = AttachableStatus.Attached; int index = PrioritySortUtil.GetDecSeqRefArrayInsertIndex <GEventListenerWrapper>(priority, eventListenerList); eventListenerList.Insert(index, listenerWrapper); ret = true; return(ret); }