Exemplo n.º 1
0
    private void Awake()
    {
        //Set the player variable to the player in the scene
        player = GameObject.FindGameObjectWithTag("player");

        gameMng = GameObject.Find("GameManager").GetComponent <GameManagerHandler>();
        pathHnd = GameObject.Find("Pathfinder").GetComponent <PathfindingHandler>();

        //Set the agentRigidBody variable to the rigidbody attached to the gameobject which the handler is attached to
        agentRigidBody = gameObject.GetComponent <Rigidbody>();

        //Initialize the new behavior tree
        test = new BehaviorTree(this);

        //Add the root to the behavior tree
        test.AddRoot();

        test.DynamicAddNode(new SequenceSelector(0, "loneEvent", this), "root");

        test.DynamicAddNode(new VisionLeaf(0, "visionLone", this), "loneEvent");
        test.DynamicAddNode(new SoleInteractionLeaf(1, "loneInteraction", this), "loneEvent");

        //Add Sequence selector to handle the attack sequence
        test.DynamicAddNode(new SequenceSelector(1, "attackSequence", this), "root");

        //Attack Sequence Leaf Nodes
        test.DynamicAddNode(new VisionLeaf(0, "vision", this), "attackSequence");
        test.DynamicAddNode(new ChaseLeaf(1, "chase", this), "attackSequence");
        test.DynamicAddNode(new OpenDoorLeaf(2, "doorAttack", this), "attackSequence");
        test.DynamicAddNode(new AttackLeaf(3, "attack", this), "attackSequence");

        //Patrol Sequence
        test.DynamicAddNode(new SequenceSelector(2, "patrolSequence", this), "root");

        //Patrol Sequence Leaf Nodes
        test.DynamicAddNode(new OpenDoorLeaf(0, "doorPatrol", this), "patrolSequence");
        test.DynamicAddNode(new PatrolLeaf(1, "patrol", this), "patrolSequence");
    }