コード例 #1
0
        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);
        }
コード例 #2
0
        private bool _DetachListenerSync(int inEventKey, IGEventListener inListener)
        {
            bool ret = false;

            if (inListener == null)
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._DetachListenerSync: inLogicNode is null");
                return(ret);
            }

            List <GEventListenerWrapper> listenerWrappers = null;

            if (!mEventListenerMap.TryGetValue(inEventKey, out listenerWrappers))
            {
                //请替换成你的log函数//
                Log.LMN.LogUtil.Error("ObjLogicNode._DetachListenerSync: no event listener for -> {0} on {1}", inEventKey, inListener);
                return(ret);
            }

            //快速找出需要移除的节点位置,注意这里其实兼顾了同一优先级节点的GC功能//
            int priority = inListener.GetPriority(inEventKey);
            int index    = PrioritySortUtil.GetDecSeqRefArrayFirstIndex <GEventListenerWrapper>(priority, listenerWrappers);
            List <GEventListenerWrapper> listenersToRemove = new List <GEventListenerWrapper>();

            for (int i = index; i < listenerWrappers.Count && listenerWrappers[i].PriorityVal == priority; i++)
            {
                GEventListenerWrapper wrapper = listenerWrappers[i];
                object listenerObj            = wrapper.mEventListenerWeakRef.Target;
                if (listenerObj == null || listenerObj == inListener)
                {
                    listenersToRemove.Add(wrapper);
                }
            }

            for (int i = 0; i < listenersToRemove.Count; i++)
            {
                listenerWrappers.Remove(listenersToRemove[i]);
            }

            inListener.ListenerStatus = AttachableStatus.Detached;

            ret = listenersToRemove.Count != 0;
            return(ret);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }