コード例 #1
0
        public override void OnStart()
        {
            m_CompositeNode = Node as CompositeNode;

            if (m_CompositeNode.Childs.Count != 3)
            {
                m_CompositeNode.Status = ENodeStatus.Error;
                return;
            }
        }
コード例 #2
0
        public override void OnAwake()
        {
            EnumField successPolicy = NodeData["SuccessType"] as EnumField;
            EnumField failedPolicy  = NodeData["FailType"] as EnumField;

            if (successPolicy == null || failedPolicy == null)
            {
                Node.Status = ENodeStatus.Error;
                return;
            }

            m_SuccessPolicy = (SUCCESS_POLICY)successPolicy.Value;
            m_FailurePolicy = (FAILURE_POLICY)failedPolicy.Value;

            m_CompositeNode = Node as CompositeNode;
        }
コード例 #3
0
        public override void OnStart()
        {
            m_CompositeNode = Node as CompositeNode;

            m_CompositeNode.RunningNodeIndex = 0;
            m_Children.Clear();
            for (int i = 0; i < m_CompositeNode.Childs.Count; i++)
            {
                m_Children.Add(m_CompositeNode.Childs[i]);
            }

            int count = m_CompositeNode.Childs.Count;

            for (int index = 0; index < count; index++)
            {
                int      randIndex = m_Random.Next(index, count);
                BaseNode childNode = m_Children[randIndex];
                m_Children[randIndex] = m_Children[index];
                m_Children[index]     = childNode;
            }
        }
コード例 #4
0
        public override void OnStart()
        {
            if (m_PriorityList == null || m_PriorityList.Count == 0)
            {
                Node.Status = ENodeStatus.Error;
                return;
            }

            m_CompositeNode = Node as CompositeNode;

            Children.Clear();
            for (int i = 0; i < m_CompositeNode.Childs.Count; i++)
            {
                Children.Add(m_CompositeNode.Childs[i]);
            }

            //先计算权重总和
            int prioritySum = 0;

            for (int index = 0; index < m_PriorityList.Count; index++)
            {
                prioritySum += m_PriorityList[index];
            }

            m_RandomList.Clear();

            //遍历所有权重
            for (int index = 0; index < m_PriorityList.Count; index++)
            {
                //从 0 到最大权重随出一个随机数
                int randIndex = m_Random.Next(0, prioritySum);
                //随机数 + 节点权重值 = 本次权重值
                int priority = randIndex + m_PriorityList[index];
                int pos      = 0;

                BaseNode childNode = Children[index];

                //记录
                PriorityIndex.Add(childNode, priority);

                //插入排序
                if (m_RandomList.Count == 0)
                {
                    //插入第一个节点
                    m_RandomList.Add(childNode);
                }
                else
                {
                    for (int i = 0; i < m_RandomList.Count; i++)
                    {
                        //最大的一端开始向下遍历,插入到第一个小于自己权重节点的位置
                        pos = i;
                        if (priority > PriorityIndex[m_RandomList[i]])
                        {
                            break;
                        }
                        pos++;
                    }
                    //插入节点
                    m_RandomList.Insert(pos, childNode);
                }
            }

            m_SelectorNode = m_RandomList[0];
        }
コード例 #5
0
 public override void OnStart()
 {
     m_CompositeNode = Node as CompositeNode;
     m_CompositeNode.RunningNodeIndex = m_Random.Next(0, m_CompositeNode.Childs.Count);
 }
コード例 #6
0
        /// <summary>
        /// 构建节点
        /// </summary>
        /// <param name="nodeData">节点数据</param>
        public BaseNode CreateNode(NodeData nodeData)
        {
            if (nodeData == null)
            {
                string msg = "BehaviorTreeManager.CreateNode() \n nodeData is null.";
                LogError(msg);
                throw new Exception(msg);
            }

            ProxyData proxyData = null;

            for (int i = 0; i < m_ProxyManagers.Count; i++)
            {
                IProxyManager proxyManager = m_ProxyManagers[i];
                proxyData = proxyManager.GetProxyData(nodeData.ClassType);
                if (proxyData != null)
                {
                    break;
                }
            }

            if (proxyData == null)
            {
                string msg = "BehaviorTreeManager.CreateNode() \n proxyData is null.";
                LogError(msg);
                throw new Exception(msg);
            }

            BaseNode baseNode = null;

            switch (proxyData.NodeType)
            {
            case ENodeType.Action:
                ActionNode actionNode = new ActionNode();
                actionNode.NodeType = ENodeType.Action;
                baseNode            = actionNode;
                break;

            case ENodeType.Composite:
                CompositeNode compositeNode = new CompositeNode();
                compositeNode.NodeType = ENodeType.Composite;
                baseNode = compositeNode;
                break;

            case ENodeType.Condition:
                ConditionNode conditionNode = new ConditionNode();
                conditionNode.NodeType = ENodeType.Condition;
                baseNode = conditionNode;
                break;

            case ENodeType.Decorator:
                DecorateNode decorateNode = new DecorateNode();
                decorateNode.NodeType = ENodeType.Condition;
                baseNode = decorateNode;
                break;
            }

            if (baseNode == null)
            {
                //组合节点必须有子节点
                string msg = $"CreateNode {proxyData.ClassType} Failed";
                LogError(msg);
                throw new Exception(msg);
            }

            baseNode.SetData(nodeData);
            baseNode.SetProxyData(proxyData);

            if (baseNode is CompositeNode)
            {
                if (nodeData.Childs == null || nodeData.Childs.Count == 0)
                {
                    //组合节点必须有子节点
                    string msg = $"{proxyData.NodeType} node must have child nodes";
                    LogError(msg);
                    throw new Exception(msg);
                }

                CompositeNode compositeNode = baseNode as CompositeNode;
                for (int i = 0; i < nodeData.Childs.Count; i++)
                {
                    NodeData childNodeData = nodeData.Childs[i];
                    BaseNode childNode     = CreateNode(childNodeData);
                    compositeNode.AddChild(childNode);
                }
            }

            return(baseNode);
        }
コード例 #7
0
 public override void OnStart()
 {
     m_CompositeNode = Node as CompositeNode;
     CurTime         = 0;
 }
コード例 #8
0
 public override void OnStart()
 {
     m_CurFrames     = 0;
     m_CompositeNode = Node as CompositeNode;
 }