// Use this for initialization
    void Start()
    {
        eventManager = FindObjectOfType <EventManager>();
        navAgent     = GetComponent <NavMeshAgent>();
        player       = FindObjectOfType <Player>();
        body         = GetComponent <Rigidbody>();
        triggerTag   = "Player";
        m_waypoints.TrimExcess();
        Debug.Log("Start target tag: " + triggerTag);

        animator = GetComponent <Animator>();

        // Detects if eye location is set
        if (!m_eyeLocation)
        {
            Debug.Log("Eye Location is not set");
        }

        // Detects if waypoints are set
        if (m_waypoints.Count < 1)
        {
            Debug.Log("Waypoints are not set");
        }

        //----------------------------------------------------
        // The Attack Sequence

        // Set triggers to turn off
        List <string> offTriggers = new List <string>();

        offTriggers.Add("Search");
        offTriggers.Add("Chase");

        // Set up the attack behaviour
        PlayAnimation attackAnimation = new PlayAnimation();

        attackAnimation.SetParameters(animator, "DeathSequence", offTriggers);

        // Set up condition for the attack sequence
        Triggered attackCondition = new Triggered();

        // Set up attack sequence
        Sequence attackSequence = new Sequence();

        attackSequence.addBehaviour(attackCondition);
        attackSequence.addBehaviour(attackAnimation);

        // ---------------------------------------------------
        // The Drill Sequence

        // Set up the drill condition
        DrillBehaviour drillBehaviour = new DrillBehaviour();

        drillBehaviour.SetParameters(false);

        // Set up drill animation
        PlayAnimation drillAnimation = new PlayAnimation();

        drillAnimation.SetParameters(animator, "DrillSequence", null, onDoorDrilling);

        // Set up drill sequence
        Sequence drillSequence = new Sequence();

        drillSequence.addBehaviour(drillBehaviour);
        //drillSequence.addBehaviour(seekPanel);
        drillSequence.addBehaviour(drillAnimation);

        // ---------------------------------------------------
        // The Rage Sequence

        // Set up the rage condition
        DrillBehaviour rageBehaviour = new DrillBehaviour();

        rageBehaviour.SetParameters(true);

        // Set up rage animation
        PlayAnimation rageAnimation = new PlayAnimation();

        rageAnimation.SetParameters(animator, "RageSequence");

        // Set up rage sequence
        Sequence rageSequence = new Sequence();

        rageSequence.addBehaviour(rageBehaviour);
        rageSequence.addBehaviour(rageAnimation);

        //----------------------------------------------------
        // The Proximity Sequence

        // Set up within range condition for search sequence
        WithinRange withinSearch = new WithinRange();

        withinSearch.SetParameters(player.gameObject, m_searchRange);

        // Set up line of sight condition for search sequence
        LineOfSight inSight = new LineOfSight();

        inSight.SetParameters(player.gameObject, m_sightRange, m_eyeLocation);

        // Set up the close chase behaviour
        SetTargetBehaviour closeChase = new SetTargetBehaviour();

        closeChase.SetParameters(player.gameObject, m_searchSpeed, "CloseChase", onProximityDetection);

        // Set up arm extended animation
        PlayAnimation armExtended = new PlayAnimation();

        armExtended.SetParameters(animator, "ArmExtended");

        // Set up chase sequence
        Sequence closeChaseSequence = new Sequence();

        closeChaseSequence.addBehaviour(withinSearch);
        closeChaseSequence.addBehaviour(inSight);
        closeChaseSequence.addBehaviour(closeChase);
        closeChaseSequence.addBehaviour(armExtended);

        //----------------------------------------------------
        // The Search Sequence

        // Turn towards the player
        FaceTarget facePlayer = new FaceTarget();

        facePlayer.SetParameters(player.gameObject, m_rotationSpeed);

        // Set up arm extended animation
        PlayAnimation searchAnimation = new PlayAnimation();

        searchAnimation.SetParameters(animator, "Search", null, searching);

        // Set up search sequence
        Sequence searchSequence = new Sequence();

        searchSequence.addBehaviour(withinSearch);
        searchSequence.addBehaviour(facePlayer);
        searchSequence.addBehaviour(searchAnimation);

        //----------------------------------------------------
        // The Chase Sequence

        // Set up the chase behaviour
        SetTargetBehaviour chasePlayer = new SetTargetBehaviour();

        chasePlayer.SetParameters(player.gameObject, m_chaseSpeed, "Chase", chasing);

        // Set up within range condition for chase sequence
        WithinRange withinChase = new WithinRange();

        withinChase.SetParameters(player.gameObject, m_sightRange);

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(withinChase);
        chaseSequence.addBehaviour(inSight);
        chaseSequence.addBehaviour(chasePlayer);

        //----------------------------------------------------
        // The Investigate Sequence

        // Set up alert condition
        AlertCondition alertCondition = new AlertCondition();

        // Set up investigate sequence
        Sequence investigateSequence = new Sequence();

        investigateSequence.addBehaviour(alertCondition);
        investigateSequence.addBehaviour(m_investigateArea);


        //----------------------------------------------------
        // The Patrol Sequence
        // Set up the patrol targets
        Patrol patrolDestination = new Patrol();

        patrolDestination.SetParameters(m_waypoints);

        // Set up the patrol behaviour
        SetTargetBehaviour patrolBehaviour = new SetTargetBehaviour();

        patrolBehaviour.SetParameters(patrolDestination, m_patrolSpeed, "Patrol", patrolling);

        // Look for nearest waypoint then continue with the patrol from there

        //----------------------------------------------------
        // The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(drillSequence);
        mainSelector.addBehaviour(rageSequence);
        mainSelector.addBehaviour(closeChaseSequence);
        mainSelector.addBehaviour(searchSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(investigateSequence);
        mainSelector.addBehaviour(patrolBehaviour);

        // Add all sequences to the behaviour list
        m_behaviours.Add(mainSelector);
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        gameObject.tag = "Scarab";
        scarabAudio    = GetComponent <AudioSource> ();
        eventManager   = FindObjectOfType <EventManager>();
        navAgent       = GetComponent <NavMeshAgent>();
        player         = FindObjectOfType <Player>();
        body           = GetComponent <Rigidbody>();
        triggerTag     = "Player";

        m_sphereCollider = GetComponent <SphereCollider>();

        if (!animator)
        {
            animator = GetComponentInChildren <Animator>();
        }
        //m_animator = GetComponent<Animator>();

        //// Setting layers for Dr Leben's parts
        //foreach (Transform child in transform)
        //    child.gameObject.layer = gameObject.layer;

        // ---------------------------------------------------
        // The Death Sequence

        // Set up the
        IsScarabAttacked deathCheck = new IsScarabAttacked();

        Sequence deathSequence = new Sequence();

        deathSequence.addBehaviour(deathCheck);

        //----------------------------------------------------
        // The Attack Sequence

        //// Set up condition for the attack sequence
        //Triggered attackCondition = new Triggered();

        // Set up within range condition for chase sequence
        WithinRange withinAttack = new WithinRange();

        withinAttack.SetParameters(player.gameObject, m_attackRange);

        // Set Up Continue attack condition
        ContinueAttack continueAttackCondition = new ContinueAttack();

        // Set up the attack behaviour
        ScarabAttack attackBehaviour = new ScarabAttack();

        attackBehaviour.SetParameters(player, m_damage, m_attackTimer, m_rotationSpeed, onAttack);

        // Set up line of sight condition for chase sequence
        LineOfSight inSight = new LineOfSight();

        inSight.SetParameters(player.gameObject, m_sightRange, m_eyeLocation);

        //// Set up component check enabled
        //ComponentEnabled navAgentCheck = new ComponentEnabled();
        //navAgentCheck.SetParameters(navMesh);

        // Set up attack sequence
        Sequence attackSequence = new Sequence();

        attackSequence.addBehaviour(continueAttackCondition);
        //attackSequence.addBehaviour(navAgentCheck);
        //attackSequence.addBehaviour(attackCondition);
        attackSequence.addBehaviour(withinAttack);
        attackSequence.addBehaviour(inSight);
        //attackSequence.addBehaviour(facePlayer);
        attackSequence.addBehaviour(attackBehaviour);

        //----------------------------------------------------
        // The Face Target Sequence

        // Set up face target behaviour
        FaceTarget facePlayer = new FaceTarget();

        facePlayer.SetParameters(player.gameObject, m_rotationSpeed);

        // Set up attack sequence
        Sequence faceTargetSequence = new Sequence();

        faceTargetSequence.addBehaviour(continueAttackCondition);
        faceTargetSequence.addBehaviour(withinAttack);
        faceTargetSequence.addBehaviour(facePlayer);

        //----------------------------------------------------
        // The Chase Sequence

        // Set up the chase behaviour
        SetTargetBehaviour chasePlayer = new SetTargetBehaviour();

        chasePlayer.SetParameters(player.gameObject, m_chaseSpeed, "", chasing);

        // Set up within range condition for chase sequence
        WithinRange withinChase = new WithinRange();

        withinChase.SetParameters(player.gameObject, m_chaseRange);

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(continueAttackCondition);
        //chaseSequence.addBehaviour(navAgentCheck);
        chaseSequence.addBehaviour(withinChase);
        chaseSequence.addBehaviour(chasePlayer);

        //----------------------------------------------------
        // The Wander Sequence
        WanderTarget wanderSetter = new WanderTarget();

        SetTargetBehaviour wanderBehaviour = new SetTargetBehaviour();

        wanderBehaviour.SetParameters(wanderSetter, m_wanderSpeed, "", wandering);

        // Set up wander sequence
        Sequence wanderSequence = new Sequence();

        //wanderSequence.addBehaviour(navAgentCheck);
        wanderSequence.addBehaviour(wanderBehaviour);

        ////----------------------------------------------------
        //// The Attack Selector

        //// Set up main selector
        //Selector attackSelector = new Selector();
        //attackSelector.addBehaviour(attackSequence);
        //attackSelector.addBehaviour(chaseSequence);

        //----------------------------------------------------
        // The Sequence Selector


        // Set up main sequence
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(deathSequence);
        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(wanderSequence);

        // Add all sequences to the behaviour list
        m_behaviours.Add(mainSelector);

        // correct position so it always sits on navmesh
        NavMeshHit closestHit;

        if (NavMesh.SamplePosition(gameObject.transform.position, out closestHit, 500f, NavMesh.AllAreas))
        {
            gameObject.transform.position = closestHit.position;
        }
        else
        {
            Debug.LogError("Could not find position on NavMesh!");
        }
    }