コード例 #1
0
        public void Awake()
        {
            Blackboard blackboard = GetComponent <Blackboard>();

            // Create the nodes
            var mainSelTask = new SelectorTask();

            mainSelTask.blackboard = blackboard;

            var seqAmmoTask = new SequenceTask();

            seqAmmoTask.blackboard = blackboard;

            var seqShootingTask = new SequenceTask();

            seqShootingTask.blackboard = blackboard;

            var movePlayerTask = new MoveToPlayerTask();

            movePlayerTask.blackboard = blackboard;

            var playerCloseTask = new PlayerIsCloseTask();

            playerCloseTask.threshold  = 5;
            playerCloseTask.blackboard = blackboard;

            var moveAmmoTask = new MoveToAmmoTask();

            moveAmmoTask.blackboard = blackboard;

            var stayTask = new StayStillTask();

            stayTask.blackboard = blackboard;

            var hasAmmoTask = new HasAmmoTask();

            hasAmmoTask.blackboard = blackboard;

            var shootTask = new ShootTask();

            shootTask.blackboard = blackboard;

            var notTask = new NotTask();

            notTask.blackboard = blackboard;

            var forTask = new ForTask();

            forTask.nRepeat    = 5;
            forTask.blackboard = blackboard;

            var waitTask = new WaitTask();

            waitTask.blackboard = blackboard;

            var playSfxTask = new PlaySfxTask();

            playSfxTask.blackboard = blackboard;
            playSfxTask.source     = this.GetComponent <AudioSource>();

            // Connect the nodes to create the tree
            rootTask = mainSelTask;
            mainSelTask.children.Add(seqAmmoTask);
            mainSelTask.children.Add(seqShootingTask);
            mainSelTask.children.Add(movePlayerTask);

            seqAmmoTask.children.Add(notTask);
            notTask.children.Add(hasAmmoTask);
            seqAmmoTask.children.Add(moveAmmoTask);

            seqShootingTask.children.Add(playerCloseTask);
            seqShootingTask.children.Add(stayTask);
            seqShootingTask.children.Add(forTask);
            forTask.children.Add(waitTask);
            waitTask.children.Add(shootTask);
            seqShootingTask.children.Add(playSfxTask);
        }
コード例 #2
0
        void Awake()
        {
            BlackBoard blackBoardRef = GetComponent <BlackBoard>();

            resourceDataRef = GameObject.FindGameObjectWithTag("ResourceGold").GetComponent <ResourceData>();

            // Create the Nodes

            var mainSelTask = new SelectorTask();

            mainSelTask.blackboardRef = blackBoardRef;

            var seqResourceTask = new SequenceTask();

            seqResourceTask.blackboardRef = blackBoardRef;

            var seqBaseTask = new SequenceTask();

            seqBaseTask.blackboardRef = blackBoardRef;

            var moveToResource = new MoveToResourceTask();

            moveToResource.blackboardRef = blackBoardRef;

            var moveToBase = new MoveToBaseTask();

            moveToBase.blackboardRef = blackBoardRef;

            var notTask = new NotTask();

            notTask.blackboardRef = blackBoardRef;

            var hasResourceTask = new HasResources();

            hasResourceTask.blackboardRef = blackBoardRef;

            var playerBaseCloseTask = new PlayerBaseIsCloseTask();

            playerBaseCloseTask.blackboardRef = blackBoardRef;

            var stayTask = new StayStillTask();

            stayTask.blackboardRef = blackBoardRef;

            var forTask = new ForTask();

            forTask.blackboardRef = blackBoardRef;

            var waitTask = new WaitTask();

            waitTask.blackboardRef = blackBoardRef;

            var goldTask = new Gold();

            goldTask.blackboardRef = blackBoardRef;


            //Connect the nodes to generate the tree
            rootTask = mainSelTask;
            mainSelTask.children.Add(seqResourceTask);
            mainSelTask.children.Add(seqBaseTask);
            mainSelTask.children.Add(moveToBase);

            seqResourceTask.children.Add(notTask);
            notTask.children.Add(hasResourceTask);
            seqResourceTask.children.Add(moveToResource);

            seqBaseTask.children.Add(playerBaseCloseTask);
            seqBaseTask.children.Add(stayTask);
            seqBaseTask.children.Add(forTask);

            forTask.children.Add(waitTask);
            waitTask.children.Add(goldTask);
        }