// Use this for initialization
    void Start()
    {
        patrolBehaviour = GetComponent <PatrolBehaviour>();

        IEnemyComplexAttackBehaviour[] complexBehaviours = GetComponents <IEnemyComplexAttackBehaviour>();
        if (complexBehaviours.Length > 0)
        {
            complexEngageBehaviour = complexBehaviours[0];
            complexEngageBehaviour.OnPlayerDetected   += Engage;
            complexEngageBehaviour.OnPlayerUnDetected += Patrol;

            isUsingComplexBehaviour = true;
        }
        else
        {
            engageBehaviour = GetComponent <IEnemyAgressiveBehaviour>();

            engageBehaviour.OnPlayerDetected   += Engage;
            engageBehaviour.OnPlayerUnDetected += Patrol;
        }

        patrolBehaviour.enabled = true;
        Behaviour behaviour = ((isUsingComplexBehaviour ? complexEngageBehaviour : engageBehaviour)) as Behaviour;

        behaviour.enabled = true;
    }
Ejemplo n.º 2
0
 new void Start()
 {
     base.Start();
     pb            = GetComponent <PatrolBehaviour> ();
     SomeoneInside = Chase;
     NooneInside   = NoChase;
 }
Ejemplo n.º 3
0
 private void Awake()
 {
     patrolBehaviour         = GetComponent <PatrolBehaviour>();
     chaseBehaviour          = GetComponent <ChaseBehaviour>();
     patrolBehaviour.enabled = true;
     chaseBehaviour.enabled  = false;
 }
Ejemplo n.º 4
0
    public IEnumerator ChangeState(PatrolBehaviour pb)
    {
        pb.isPausing = true;
        Debug.Log("Pausing");
        yield return(new WaitForSeconds(pb.waitTime));

        Debug.Log("Finished Pausing");
        pb.isPausing = false;
    }
 new protected void Start()
 {
     base.Start();
     pb            = GetComponent <PatrolBehaviour> ();
     cb            = GetComponent <EnemyChasingBehaviour> ();
     SomeoneInside = Attack;
     NooneInside   = NoAttack;
     EveryUpdate   = AllUpdates;
 }
    new void Start()
    {
        base.Start();
        pb            = GetComponent <PatrolBehaviour>();
        SomeoneInside = Chase;
        NooneInside   = NoChase;

        // 2 case: 1 at start and it's false. 2 when a wave is spawn and could be the boss near the cell or the waves for the alarm.
        CheckTheAlarm();
    }
    protected override void Start()
    {
        base.Start();

        flip            = GetComponent <Flip>();
        patrolBehaviour = GetComponent <PatrolBehaviour>();
        mover           = GetComponent <Mover>();
        fighter         = GetComponent <Fighter>();
        anim            = GetComponent <Animator>();

        currentState = State.Death;
    }
    void Awake()
    {
        _motor    = transform.parent.GetComponent <EnemyMovementMotor>();
        _animator = transform.parent.GetComponent <EnemyAnimatorController>();
        _health   = transform.parent.GetComponent <EnemyHealth>();

        _soundBank  = transform.parent.GetComponentInChildren <EnemySoundBank>();
        _pathFinder = transform.parent.GetComponentInChildren <PathFinder>();

        _patrolAi  = GetComponent <PatrolBehaviour>();
        _pursueAi  = GetComponent <PursueBehaviour>();
        _exploreAi = GetComponent <ExploreBehaviour>();
    }
    protected override void Start()
    {
        base.Start();
        currentState = State.Death;

        enemyDetector   = GetComponentInChildren <EnemyDetector>();
        patrolBehaviour = GetComponent <PatrolBehaviour>();
        chaseBehaviour  = GetComponent <ChaseBehaviour>();
        mover           = GetComponent <Mover>();
        fighter         = GetComponent <Fighter>();
        anim            = GetComponent <Animator>();

        enemyDetector.PlayerDetected.AddListener(UpdateTarget);
        enemyDetector.PlayerLost.AddListener(UpdateTarget);
    }
Ejemplo n.º 10
0
    private BaseState GetBehaviour(AIBehaviour behaviour)
    {
        BaseState retVal = null;

        switch (behaviour)
        {
        case AIBehaviour.Patrolling:
            retVal = new PatrolBehaviour(this);
            break;

        case AIBehaviour.Wander:
            retVal = new WanderBehaviour(this);
            break;

        case AIBehaviour.Skirmish:
            retVal = new SkirmishBehaviour(this);
            break;

        case AIBehaviour.ChargeTarget:
            retVal = new BerserkerBehaviour(this);
            break;

        case AIBehaviour.Cover:
            retVal = new TacticalBehaviour(this);
            break;

        case AIBehaviour.MoveToTransform:
            retVal = new MoveToTransformBehaviour(this);
            break;

        case AIBehaviour.Chase:
            retVal = new ChaseState(this);
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(behaviour), behaviour, null);
        }

        retVal.Enter();

        return(retVal);
    }
Ejemplo n.º 11
0
 public void DoCoroutine(PatrolBehaviour pb)
 {
     StartCoroutine("ChangeState", pb);
 }
    // Use this for initialization
    void Start()
    {
        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();

        currentHealth = maxHealth;

        //-----------------------------------------------------------------
        // The Flee Sequence

        // Set up the flee force and flee force parameter
        m_fleeForce = new HorizontalFleeForce();
        m_fleeForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the flee behaviour
        fleeBehaviour = new SteeringBehaviour();
        fleeBehaviour.Constructor();
        fleeBehaviour.AddNewForce(m_fleeForce);

        // Set up condition for flee sequence
        WithinRange fleeCondition = new WithinRange();

        fleeCondition.SetParameters(player, 1.5f);

        // Set up flee sequence
        Sequence fleeSequence = new Sequence();

        fleeSequence.addBehaviour(fleeCondition);
        fleeSequence.addBehaviour(fleeBehaviour);

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

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

        attackBehaviour.SetTarget(player);
        attackBehaviour.SetWeaponType(ShootBehaviour.WeaponType.HitScanType);
        List <GameObject> guns = new List <GameObject>();

        // Give a list of bullet spawners to the shoot behaviour
        foreach (Transform child in transform)
        {
            GunParticleSystem gun;
            gun = child.gameObject.GetComponent <GunParticleSystem>();
            if (gun != null)
            {
                guns.Add(gun.gameObject);
            }
        }
        attackBehaviour.SetGuns(guns);

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

        attackCondition.SetParameters(player, attackRange);

        // Set up play sound behaviour
        PlaySound playAttackSound = new PlaySound();

        if (stateAudioSource != null && attackStateClip != null)
        {
            playAttackSound.SetAudioSource(stateAudioSource);
            playAttackSound.SetAudioClip(attackStateClip);
            playAttackSound.SetTimer(15.0f);
        }

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

        attackSequence.addBehaviour(attackCondition);
        if (stateAudioSource != null && attackStateClip != null)
        {
            attackSequence.addBehaviour(playAttackSound);
        }
        attackSequence.addBehaviour(attackBehaviour);



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

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, chaseRange);

        // Set up play sound behaviour
        PlaySound playChaseSound = new PlaySound();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            playChaseSound.SetAudioSource(stateAudioSource);
            playChaseSound.SetAudioClip(chaseStateClip);
            playChaseSound.SetTimer(15.0f);
        }

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

        chaseSequence.addBehaviour(chaseCondition);
        if (stateAudioSource != null && chaseStateClip != null)
        {
            chaseSequence.addBehaviour(playChaseSound);
        }
        chaseSequence.addBehaviour(seekBehaviour);



        //----------------------------------------------------------------
        // The Patrol Sequence

        // Set up patrol behaviour
        PatrolBehaviour patrol = new PatrolBehaviour();

        patrol.SetPatrolPoints(m_patrolPointA, m_patrolPointB);
        patrol.StartUp();

        // Set up play sound behaviour
        PlaySound playPatrolSound = new PlaySound();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            playPatrolSound.SetAudioSource(stateAudioSource);
            playPatrolSound.SetAudioClip(patrolStateClip);
            playPatrolSound.SetTimer(15.0f);
        }

        // Set up patrol sequence
        Sequence patrolSequence = new Sequence();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            chaseSequence.addBehaviour(playPatrolSound);
        }
        patrolSequence.addBehaviour(patrol);

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

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

        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(patrolSequence);



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

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
Ejemplo n.º 13
0
    // Use this for initialization
    void Start()
    {
        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();


        //-----------------------------------------------------------------
        // The Collision Avoidance Sequence

        // Set up the collsion avoidance force



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

        //// Set up the attack behaviour
        //ShootBehaviour m_attackBehaviour = new ShootBehaviour();


        //// Set up condition for the attack sequence
        //WithinRange attackCondition = new WithinRange();
        //attackCondition.SetParameters(player, 5);

        //// Set up attack sequence
        //Sequence attackSequence = new Sequence();
        //attackSequence.addBehaviour(attackCondition);
        //attackSequence.addBehaviour(m_attackBehaviour);



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

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, 20);

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

        chaseSequence.addBehaviour(chaseCondition);
        chaseSequence.addBehaviour(seekBehaviour);



//----------------------------------------------------------------
// The Patrol Sequence

        // Set up patrol behaviour
        PatrolBehaviour patrol = new PatrolBehaviour();

        patrol.StartUp();
        patrol.SetPatrolPoints(new Vector3(20, 3, 12), new Vector3(-20, 3, 12));



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

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

        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(patrol);



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

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
Ejemplo n.º 14
0
    public void OnSceneGUI()
    {
        PatrolBehaviour owner = (PatrolBehaviour)target;
        Event           e     = Event.current;

        Ray     ray         = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
        Vector2 vWorldMouse = ray.origin;

        if (e.type == EventType.MouseUp)
        {
            m_allowNodeCreation = true;
            if (m_moveBackToSavedPos)
            {
                owner.transform.position = m_savedPosition;
            }
        }
        else if (e.type == EventType.MouseDown)
        {
            m_moveBackToSavedPos = false;
            m_savedPosition      = owner.transform.position;
        }

        if (!Application.isPlaying)
        {
            owner.BasePos = owner.transform.position;
        }

        if (owner.Path != null)
        {
            for (int i = 0; i < owner.Path.Count; ++i)
            {
                Vector3 vPathPos      = owner.Path[i];
                Vector3 vDiff         = m_moveBackToSavedPos ? owner.BasePos - m_savedPosition : Vector3.zero;
                Vector3 vWorldPathPos = owner.BasePos + vPathPos - vDiff;
                if (owner.WrapMode == PatrolBehaviour.eMode.Loop || (i != (owner.Path.Count - 1)))
                {
                    Handles.color = Color.white;
                    Handles.DrawLine(vWorldPathPos, owner.BasePos + (Vector3)owner.Path[(i + 1) % owner.Path.Count] - vDiff);
                }

                EditorGUI.BeginChangeCheck();
                Handles.color = Color.white;
                if (
                    !Application.isPlaying &&
                    owner.Path.Count > 2 &&
                    e.control &&
                    Vector2.Distance(vWorldPathPos, vWorldMouse) <= 0.15f * HandleUtility.GetHandleSize(vPathPos)
                    )
                {
                    Handles.color = Color.red;
                    // remove node only if mouse button is released and node was not changed
                    // to avoid removing the node when the intention was snapping the node position
                    if (e.type == EventType.MouseUp && !m_moveBackToSavedPos)
                    {
                        owner.Path.RemoveAt(i);
                        --i;
                        continue;
                    }
                }
                vPathPos += Handles.FreeMoveHandle(vWorldPathPos, Quaternion.identity, 0.15f * HandleUtility.GetHandleSize(vPathPos), Vector3.zero, EditorCompatibilityUtils.SphereCap) - vWorldPathPos;
                if (EditorGUI.EndChangeCheck() && !Application.isPlaying)
                {
                    if (e.control)
                    {
                        vPathPos.x = Mathf.Round(vPathPos.x / EditorPrefs.GetFloat("MoveSnapX")) * EditorPrefs.GetFloat("MoveSnapX");
                        vPathPos.y = Mathf.Round(vPathPos.y / EditorPrefs.GetFloat("MoveSnapY")) * EditorPrefs.GetFloat("MoveSnapY");
                    }

                    if (e.shift && m_allowNodeCreation)
                    {
                        owner.Path.Insert(i, vPathPos);
                        ++i;
                    }
                    else
                    {
                        owner.Path[i] = vPathPos;
                    }
                    m_allowNodeCreation      = false;
                    m_moveBackToSavedPos     = true;
                    owner.transform.position = owner.BasePos + vPathPos - vDiff;
                }
            }
        }

        SceneView.RepaintAll();
        serializedObject.ApplyModifiedProperties();
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Ejemplo n.º 15
0
    void Start()
    {
        //VARIABLES
        lookB         = GetComponent <LookAroundBehaviour>();
        patrolB       = GetComponent <PatrolBehaviour>();
        chaseB        = GetComponent <ChaseBehaviour>();
        atkB          = GetComponent <AttackBehaviour>();
        coneVision    = GetComponent <ConeVision>();
        fsmCurrentTxt = fsmCurrentTxt.GetComponent <TextMeshProUGUI>();
        velocity      = GetComponent <Velocity>();
        health        = GetComponent <HealthBar>();

        //STATES
        FSMState Start        = new FSMState();
        FSMState lookAround   = new FSMState();
        FSMState patrol       = new FSMState();
        FSMState lastPosition = new FSMState();
        FSMState chase        = new FSMState();
        FSMState attack       = new FSMState();


        //ACTIONS
        Start.enterActions.Add(StartAction);

        lookAround.enterActions.Add(LookAround);
        lookAround.exitActions.Add(lookB.StopLooking);

        patrol.enterActions.Add(Patrol);
        patrol.exitActions.Add(patrolB.StopPatrol);

        chase.enterActions.Add(Chase);
        chase.exitActions.Add(chaseB.StopAtLastKnowPosition);

        lastPosition.enterActions.Add(LastPosition);

        attack.enterActions.Add(chaseB.StopNow);
        attack.enterActions.Add(Attack);
        attack.exitActions.Add(atkB.StopAttacking);

        //TRANSITIONS
        FSMTransition t0 = new FSMTransition(AlwaysTrue);
        FSMTransition t1 = new FSMTransition(PlayerHidden);
        FSMTransition t2 = new FSMTransition(PlayerDetected);
        FSMTransition t3 = new FSMTransition(PlayerNotDetected);
        FSMTransition t4 = new FSMTransition(PlayerInAttackRange);
        FSMTransition t5 = new FSMTransition(PlayerNotInAttackRange);
        FSMTransition t6 = new FSMTransition(PatrolingFinished);
        FSMTransition t7 = new FSMTransition(NotMoving);
        FSMTransition t8 = new FSMTransition(PlayerNotHidden);

        //LINK STATE - TRANSITION
        Start.AddTransition(t0, patrol);

        lookAround.AddTransition(t1, patrol);
        lookAround.AddTransition(t8, chase);
        lookAround.AddTransition(t2, chase);

        patrol.AddTransition(t2, chase);
        patrol.AddTransition(t6, lookAround);

        chase.AddTransition(t3, lastPosition);
        chase.AddTransition(t4, attack);

        lastPosition.AddTransition(t7, lookAround);
        lastPosition.AddTransition(t2, chase);

        attack.AddTransition(t5, chase);

        //INITIAL STATE
        fsm = new FSM(Start);
        StartCoroutine(Run());
    }