예제 #1
0
    /// <summary>
    /// 初始化添加行为树节点
    /// </summary>
    private void Init()
    {
        // 顺序节点 1
        NodeSequence nodeSequence_1 = new NodeSequence();

        // 顺序节点 1 添加到根节点
        rootNode.AddNode(nodeSequence_1);

        #region 是否饿了
        // 条件节点 1.1
        NodeConditionHungry nodeConditionHungry_1_1 = new NodeConditionHungry();
        nodeConditionHungry_1_1.SetStudent(this);
        // 条件节点 1.1 添加到 顺序节点1
        nodeSequence_1.AddNode(nodeConditionHungry_1_1);
        #endregion

        #region  择节点 1.2
        {
            // 选择节点1.2
            NodeSelect nodeSelect_1_2 = new NodeSelect();
            nodeSequence_1.AddNode(nodeSelect_1_2);

            // 节点 1.2.1 是否有饭
            NodeConditionHasFood nodeConditionHasFood_1_2_1 = new NodeConditionHasFood();
            nodeConditionHasFood_1_2_1.SetStudent(this);
            nodeSelect_1_2.AddNode(nodeConditionHasFood_1_2_1);

            // 顺序节点 1.2.2
            NodeSequence nodeSequence_1_2_2 = new NodeSequence();
            nodeSelect_1_2.AddNode(nodeSequence_1_2_2);

            // 行为节点 1.2.2.1 走到厨房
            NodeActionMove nodeActionMove_1_2_2_1 = new NodeActionMove();
            nodeActionMove_1_2_2_1.SetStudent(this);
            nodeActionMove_1_2_2_1.SetTarget("Cooking");
            nodeActionMove_1_2_2_1.SetTr(transform);
            nodeSequence_1_2_2.AddNode(nodeActionMove_1_2_2_1);

            // 行为节点 1.2.2.2 做饭
            NodeActionCooking nodeActionCooking_1_2_2_2 = new NodeActionCooking();
            nodeActionCooking_1_2_2_2.SetStudent(this);
            nodeSequence_1_2_2.AddNode(nodeActionCooking_1_2_2_2);
        }
        #endregion

        #region 走到餐桌
        {
            // 行为节点 1.3 走到餐桌
            NodeActionMove nodeActionMove_1_3 = new NodeActionMove();
            nodeActionMove_1_3.SetStudent(this);
            nodeActionMove_1_3.SetTarget("Food");
            nodeActionMove_1_3.SetTr(transform);
            nodeSequence_1.AddNode(nodeActionMove_1_3);
        }
        #endregion

        #region 吃饭
        {
            // 行为节点 1.4 吃饭
            NodeActionEat nodeActionEat_1_4 = new NodeActionEat();
            nodeActionEat_1_4.SetStudent(this);
            nodeSequence_1.AddNode(nodeActionEat_1_4);
        }
        #endregion
    }
예제 #2
0
    void Init()
    {
        NodeSequence nodeSequence_1 = new NodeSequence();

        rootNode.AddNode(nodeSequence_1);

        #region 条件 1.1 是否饿了
        {
            NodeConditionHungry cond_1_1 = new NodeConditionHungry();
            cond_1_1.SetActor(this);
            nodeSequence_1.AddNode(cond_1_1);
        }
        #endregion

        #region  择条件 1.2 是否有饭
        {
            NodeSelect sel_1_2 = new NodeSelect();
            nodeSequence_1.AddNode(sel_1_2);

            // 1.2.1 是否有饭
            NodeConditionHasFood hasFood_1_2_1 = new NodeConditionHasFood();
            hasFood_1_2_1.SetActor(this);
            sel_1_2.AddNode(hasFood_1_2_1);

            // 没有饭的话, 走去厨房 => 做饭
            // 1.2.2 顺序节点
            NodeSequence sequence_1_2_2 = new NodeSequence();
            sel_1_2.AddNode(sequence_1_2_2);
            // 1.2.2.1 走厨房
            NodeActionMove move_1_2_2_1 = new NodeActionMove();
            move_1_2_2_1.SetActor(this);
            move_1_2_2_1.myTransform     = this.transform;
            move_1_2_2_1.targetTransform = doCookingTransform;
            sequence_1_2_2.AddNode(move_1_2_2_1);
            // 1.2.2.2 做饭
            NodeActionCooking cooking_1_2_2_2 = new NodeActionCooking();
            cooking_1_2_2_2.SetActor(this);
            sequence_1_2_2.AddNode(cooking_1_2_2_2);
        }
        #endregion
        #region 1.3 去餐桌
        {
            NodeActionMove move_1_3 = new NodeActionMove();
            move_1_3.SetActor(this);
            move_1_3.myTransform     = this.transform;
            move_1_3.targetTransform = eatFoodTransform;

            nodeSequence_1.AddNode(move_1_3);
        }
        #endregion

        #region 1.4 吃饭
        {
            NodeActionEat eat_1_4 = new NodeActionEat();
            eat_1_4.SetActor(this);
            nodeSequence_1.AddNode(eat_1_4);
        }
        #endregion

        #region 2
        // 并行节点
        NodeParallel p_2 = new NodeParallel();
        rootNode.AddNode(p_2);

        // 2.1 是否有钱
        NodeConditionHasMoney hasMoney_2_1 = new NodeConditionHasMoney();
        p_2.AddNode(hasMoney_2_1);

        // 2.2 走去酒馆
        NodeSequence seq_saloon = new NodeSequence();
        p_2.AddNode(seq_saloon);

        NodeActionMove move_2_2 = new NodeActionMove();
        move_2_2.myTransform     = this.transform;
        move_2_2.targetTransform = saloonTransform;
        seq_saloon.AddNode(move_2_2);
        // 2.3 随机点一份酒水
        NodeRandom r_2_3 = new NodeRandom();
        seq_saloon.AddNode(r_2_3);
        // 2.3.1 喝红酒
        r_2_3.AddNode(new NodeActionDrinkRedWine());
        // 2.3.2 喝白开水
        r_2_3.AddNode(new NodeActionDrinkWater());
        #endregion
    }