// Start is called before the first frame update
    void Awake()
    {
        SelectorNode root = new SelectorNode();

        SequenceNode seq1  = new SequenceNode();
        Task1        task1 = new Task1(sc, pl);
        Task2        task2 = new Task2(sc, pl);

        seq1.addChild(task1);
        seq1.addChild(task2);

        SequenceNode seq2  = new SequenceNode();
        Task3        task3 = new Task3(sc, osc);
        Task4        task4 = new Task4(sc, osc);

        seq2.addChild(task3);
        seq2.addChild(task4);

        SelectorNode sel2  = new SelectorNode();
        SequenceNode seq3  = new SequenceNode();
        Task5        task5 = new Task5(sc);
        Task6        task6 = new Task6(sc);

        seq3.addChild(task5);
        seq3.addChild(task6);
        Task7 task7 = new Task7(sc);

        sel2.addChild(seq3);
        sel2.addChild(task7);

        root.addChild(seq1);
        root.addChild(seq2);
        root.addChild(sel2);

        behavior = new BehaviorTree(root);

        sc.SetDestination(sc.transform.position);
    }
    // Start is called before the first frame update
    void Start()
    {
        Self          = gameObject;
        treeFrontNode = new SelectorNode("Root");

        SequenceNode  StandNode         = new SequenceNode("Stand");
        ConditionNode isInFieldNode     = new ConditionNode("InField", IsInField);
        ConditionNode isAttackedNode    = new ConditionNode("isAttacked", IsAttacked);
        InverterNode  isNotAttackedNode = new InverterNode("isNotAttacked", isAttackedNode);
        ActionNode    standActionNode   = new ActionNode("站立", OnStandAction);

        StandNode.addChild(isInFieldNode);
        StandNode.addChild(isNotAttackedNode);
        StandNode.addChild(standActionNode);

        SequenceNode AttackNode = new SequenceNode("Attack");

        SequenceNode RebackNode = new SequenceNode("Reback");

        treeFrontNode.addChild(StandNode);
        treeFrontNode.addChild(AttackNode);
        treeFrontNode.addChild(RebackNode);
    }
Пример #3
0
    public void Start()
    {
        /*if (GameController.player == null) {
         *  GameController.player = new PlayerCharacter();
         *  Debug.LogWarning("Can't find PlayerCharacter script in the scene. This may cause issues.");
         * }*/

        takeControl = true;
        Debug.Log("Player in Move Selector: " + GameController.player.strength);

        /*if(GameController.player == null) {
         *  Debug.LogWarning("There is no fighter class attached to the move selector. I'm creating a fake player for testing purposes.");
         *  GameController.player = new PlayerCharacter();
         *  GameController.player.testInventory();
         * }*/
        if (GameController.player.name == "[Test_inv]")
        {
            GameController.player.testInventory();
        }

        MoveUtils.InitMoves();

        selections = new Dictionary <string, object>();
        types      = new Dictionary <string, string>();

        selectorMap = new Dictionary <SelectorType, GameObject>();
        selectorMap[SelectorType.Loop]     = loopObject;
        selectorMap[SelectorType.Grid]     = gridObject;
        selectorMap[SelectorType.In_Place] = inPlaceObject;

        root = new SelectorNode("root", "ROOT", new List <SelectorNode>(), SelectorType.Grid);

        SelectorNode moves = new SelectorNode("moves", "Moves", new List <SelectorNode>(), SelectorType.Loop);

        root.addChild(moves);

        foreach (Move m in GameController.player.getMoves())
        {
            selections.Add(m.name, MoveUtils.GetMove(m.name));
            types.Add(m.name, "move");
            moves.addChild(new SelectorNode(m.name, m.name));
        }

        items = new SelectorNode("items", "Items", new List <SelectorNode>(), SelectorType.Loop);
        root.addChild(items);

        if (GameController.player.inventory.Count > 0)
        {
            foreach (Item item in GameController.player.inventory)
            {
                Debug.Log(item.getName());
                if (item.getName() != "Rock" && item.getName() != "Ladder")
                {
                    selections.Add(item.getName(), item);
                    types.Add(item.getName(), "item");
                    items.addChild(new SelectorNode(item.getName(), item.getDisplayName()));
                }
            }
        }



        SelectorNode options = new SelectorNode("run", "Run");

        root.addChild(options);

        SelectorNode special = new SelectorNode("special", "Special", new List <SelectorNode>(), SelectorType.Loop);

        root.addChild(special);

        current = root;

        updateDisplay();
    }
Пример #4
0
        public override void Run()
        {
            blackBoard = new TestBlackboard(typeof(TestBlackboard.Vars));
            tree       = new TestTree(blackBoard, this);

            blackBoard.setData(TestBlackboard.Vars.FirePower, 5d);
            blackBoard.setData(TestBlackboard.Vars.LastScan, -10d);
            blackBoard.setData(TestBlackboard.Vars.ScanDelay, 5d);
            blackBoard.setData(TestBlackboard.Vars.MaxDist, 300d);

            //Build Tree
            {
                DecoratorNode repeater = new RepeatUntilWinNode();
                tree.SetMaster(repeater);
                CompositeNode sequencer = new SequenceNode();
                repeater.setChild(sequencer);
                //Scanning
                {
                    DecoratorNode scanInverter1 = new InverterNode();
                    sequencer.addChild(scanInverter1);
                    CompositeNode scanSequencer = new SequenceNode();
                    scanInverter1.setChild(scanSequencer);

                    DecoratorNode scanInverter2 = new InverterNode();
                    scanSequencer.addChild(new ChangeColorNode(Color.Blue));
                    scanSequencer.addChild(scanInverter2);
                    scanInverter2.setChild(new RecentlyScannedNode());
                    scanSequencer.addChild(new ScanNode());
                }
                CompositeNode selector = new SelectorNode();
                sequencer.addChild(selector);
                //Move to range
                {
                    CompositeNode MoveToRangeSequencer = new SequenceNode();
                    selector.addChild(MoveToRangeSequencer);

                    MoveToRangeSequencer.addChild(new ChangeColorNode(Color.Green));
                    MoveToRangeSequencer.addChild(new RecentlyScannedNode());
                    DecoratorNode MoveToRangeInverter = new InverterNode();
                    MoveToRangeSequencer.addChild(MoveToRangeInverter);
                    MoveToRangeInverter.setChild(new InRangeNode());
                    MoveToRangeSequencer.addChild(new TurnTowardsNode());
                    MoveToRangeSequencer.addChild(new DriveNode());
                }
                // Shooting
                {
                    CompositeNode shootingSequencer = new SequenceNode();
                    selector.addChild(shootingSequencer);
                    shootingSequencer.addChild(new ChangeColorNode(Color.Red));
                    shootingSequencer.addChild(new CheckGunHeatNode());
                    shootingSequencer.addChild(new ScanNode());
                    shootingSequencer.addChild(new ShootNode());
                }
                selector.addChild(new DoNothingNode());
            }
            Out.WriteLine("Created Behaviour tree");

            //Run Tree
            {
                BTNode.Status s;
                do
                {
                    s = tree.process();
                }while(s == BTNode.Status.Running);
            }
        }