Beispiel #1
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}

    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        AIStateAttack aiStateAttack = animator.GetComponent <AIStateAttack>();

        if (aiStateAttack != null)
        {
            aiStateAttack.DeactivateAllAttacks();
        }
    }
Beispiel #2
0
    private void Start()
    {
        // Getting cache variables
        _navMeshAgent     = GetComponent <NavMeshAgent>();
        _animator         = GetComponent <Animator>();
        _mouthAudioSource = GetComponent <AudioSource>();
        _targetTrigger    = GetComponentInChildren <TargetTrigger>();
        AIDecapitation[] parts = GetComponentsInChildren <AIDecapitation>();
        foreach (AIDecapitation part in parts)
        {
            _parts.Add(part);
        }

        HandleAnimatorController();

        // Getting the skinned mesh renderers for the metamorphosis
        if (_metamorphosisMaterial != null)
        {
            SkinnedMeshRenderer[] skinnedMeshRenderers = GetComponentsInChildren <SkinnedMeshRenderer>();
            foreach (SkinnedMeshRenderer meshRenderer in skinnedMeshRenderers)
            {
                _skinnedMeshRenderers.Add(meshRenderer);
            }
        }

        // We always have the rotation of the navmesh deactivated!
        // In fact, we either rotate with the root motion rotation of the turn around animation
        // Or we rotate it manually through code.
        // In sum, the navmesh is only useful for calculating the path: steertingTarget :)
        if (_navMeshAgent != null)
        {
            _navMeshAgent.updateRotation = false;
        }

        if (_targetTrigger != null)
        {
            _targetTrigger.RegisterTargetTrigger(this);
        }

        // Storing states
        AIStateIdle stateIdle = GetComponent <AIStateIdle>();

        if (stateIdle != null)
        {
            _statesDictionary.Add(AIStateType.Idle, stateIdle);
            _statesDictionary[AIStateType.Idle].RegisterState(this);
        }

        AIStatePatrol statePatrol = GetComponent <AIStatePatrol>();

        if (statePatrol != null)
        {
            _statesDictionary.Add(AIStateType.Patrol, statePatrol);
            _statesDictionary[AIStateType.Patrol].RegisterState(this);
        }

        AIStatePursuit statePursuit = GetComponent <AIStatePursuit>();

        if (statePursuit != null)
        {
            _statesDictionary.Add(AIStateType.Pursuit, statePursuit);
            _statesDictionary[AIStateType.Pursuit].RegisterState(this);
        }

        AIStateAttack stateAttack = GetComponent <AIStateAttack>();

        if (stateAttack != null)
        {
            _statesDictionary.Add(AIStateType.Attacking, stateAttack);
            _statesDictionary[AIStateType.Attacking].RegisterState(this);
        }

        AIStateAlert stateAlert = GetComponent <AIStateAlert>();

        if (stateAlert != null)
        {
            _statesDictionary.Add(AIStateType.Alert, stateAlert);
            _statesDictionary[AIStateType.Alert].RegisterState(this);
        }

        if (_statesDictionary.ContainsKey(AIStateType.Idle) && _statesDictionary[AIStateType.Idle] != null)
        {
            ChangeState(AIStateType.Idle);
        }

        // Get all body parts snapshot
        Transform[] bodyParts = transform.GetComponentsInChildren <Transform>();
        foreach (Transform bodyPart in bodyParts)
        {
            BodyPartSnapShot bodyPartSnapshot = new BodyPartSnapShot();
            bodyPartSnapshot.transform = bodyPart;
            _bodyPartsSnapshots.Add(bodyPartSnapshot);
        }

        // At the beginning, we should always be able to scream
        _screamTimer = _screamDelay;

        // Getting the navmesh agent initial speed for damageBehavior (in case we aren't using root rotation)
        if (_navMeshAgent != null)
        {
            _initialSpeed = _navMeshAgent.speed;
        }

        _initialVehicleStoppingDistance = _vehicleStoppingDistance;
    }