예제 #1
0
        public override void OnStart()
        {
            m_CompositeNode = Node as CompositeNode;

            if (m_CompositeNode.Childs.Count != 3)
            {
                m_CompositeNode.Status = NodeStatus.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 = NodeStatus.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 = NodeStatus.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_CurFrames     = 0;
     m_CompositeNode = Node as CompositeNode;
 }
예제 #6
0
 public override void OnStart()
 {
     m_CompositeNode = Node as CompositeNode;
     m_CompositeNode.RunningNodeIndex = m_Random.Next(0, m_CompositeNode.Childs.Count);
 }
예제 #7
0
 public override void OnStart()
 {
     m_CompositeNode = Node as CompositeNode;
     CurTimes        = 0;
 }
예제 #8
0
        /// <summary>
        /// 构建节点
        /// </summary>
        /// <param name="nodeData">节点数据</param>
        public BaseNode CreateNode(NodeData nodeData)
        {
            if (nodeData == null)
            {
                throw new Exception($"BehaviorTreeManager.CreateNode() \n nodeData is null.");
            }

            var proxyData = _proxyManager.GetProxyData(nodeData.ClassType);

            if (proxyData == null)
            {
                throw new Exception($"BehaviorTreeManager.CreateNode({nodeData.ClassType}) \n proxyData is null.");
            }

            BaseNode baseNode = null;

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

            case NodeType.Composite:
                baseNode = new CompositeNode {
                    NodeType = NodeType.Composite
                };
                break;

            case NodeType.Condition:
                baseNode = new ConditionNode {
                    NodeType = NodeType.Condition
                };
                break;

            case NodeType.Decorator:
                baseNode = new DecorateNode {
                    NodeType = NodeType.Condition
                };
                break;
            }

            if (baseNode == null)
            {
                throw new Exception($"CreateNode {proxyData.Name} Failed");
            }

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

            if (baseNode is CompositeNode)
            {
                if (nodeData.Childs == null || nodeData.Childs.Count == 0)
                {
                    throw new Exception($"{proxyData.NodeType} node must have child nodes");
                }

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

            return(baseNode);
        }