public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            if (status == NodeStatus.STATUS_FAILURE)
            {
                SetFailuer();
                return(m_nodeStatus);
            }
        }

        BaseBTNode runningNode = computeRunningNode(m_nodes);

        if (runningNode != null)
        {
            switch (runningNode.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                break;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                break;
            }
        }

        foreach (BaseBTNode node in m_nodes)
        {
            if (node == runningNode)
            {
                continue;
            }
            switch (node.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                continue;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                continue;
            }
        }
        m_nodeStatus = NodeStatus.STATUS_FAILURE;
        return(m_nodeStatus);
    }
Beispiel #2
0
    //ノード状態の評価
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            switch (status)
            {
            case NodeStatus.STATUS_SUCCESS:
                if (m_nodes[0] != m_preNode)
                {
                    m_preNode.SetFailuer();
                }
                m_nodeStatus = m_nodes[0].Evaluate();
                m_preNode    = m_nodes[0];
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                if (m_nodes[1] != m_preNode)
                {
                    m_preNode.SetFailuer();
                }
                m_nodeStatus = m_nodes[1].Evaluate();
                m_preNode    = m_nodes[1];
                return(m_nodeStatus);

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = m_preNode.Evaluate();
                return(m_nodeStatus);
            }
        }
        //ここにくるのはおかしい
        return(NodeStatus.STATUS_FAILURE);
    }
Beispiel #3
0
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            if (status == NodeStatus.STATUS_FAILURE)
            {
                SetFailuer();
                return(m_nodeStatus);
            }
        }

        BaseBTNode runningNode = computeRunningNode(m_nodes);

        if (runningNode != null)
        {
            m_isRunningNode = true;
        }

        //子ノードの処理を順番に実行
        foreach (BaseBTNode node in m_nodes)
        {
            if (m_isRunningNode)
            {
                if (node != runningNode)
                {
                    continue;
                }
                else
                {
                    m_isRunningNode = false;
                }
            }
            switch (node.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                continue;

            case NodeStatus.STATUS_FAILURE:
                m_nodeStatus = NodeStatus.STATUS_FAILURE;
                return(m_nodeStatus);

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);
            }
        }
        m_nodeStatus = NodeStatus.STATUS_SUCCESS;
        return(m_nodeStatus);
    }
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            if (status == NodeStatus.STATUS_FAILURE)
            {
                SetFailuer();
                return(m_nodeStatus);
            }
        }

        BaseBTNode runningNode = computeRunningNode(m_nodes);

        if (runningNode != null)
        {
            switch (runningNode.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                break;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                break;
            }
        }

        if (m_preNode != null)
        {
            m_failuerNodes.Add(m_preNode);
            m_nodes.Remove(m_preNode);
        }
        while (m_nodes.Count > 0)
        {
            int selectNode = UnityEngine.Random.Range(0, m_nodes.Count);
            switch (m_nodes[selectNode].Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                m_preNode    = m_nodes[selectNode];
                //元に戻すため
                foreach (BaseBTNode node in m_failuerNodes)
                {
                    m_nodes.Add(node);     //m_nodesにはないはず
                }
                m_failuerNodes.Clear();
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                //ランダムに選ぶものから外すため
                m_failuerNodes.Add(m_nodes[selectNode]);
                m_nodes.RemoveAt(selectNode);
                continue;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                //元に戻すため
                foreach (BaseBTNode node in m_failuerNodes)
                {
                    m_nodes.Add(node);     //m_nodesにはないはず
                }
                m_failuerNodes.Clear();
                return(m_nodeStatus);

            default:
                continue;
            }
        }
        //元に戻すため
        m_preNode = null;
        foreach (BaseBTNode node in m_failuerNodes)
        {
            m_nodes.Add(node); //m_nodesにはないはず
        }
        m_failuerNodes.Clear();
        m_nodeStatus = NodeStatus.STATUS_FAILURE;
        return(m_nodeStatus);
    }