public void SwitchState(AIState.AIStateType stateType) { if (_currentState != null) { _currentState.OnExit(); } if (_statesDictionary.TryGetValue(stateType, out _currentState)) { // No need to work on changing layers when we go into alert mode if (stateType == AIState.AIStateType.Attack || stateType == AIState.AIStateType.Pursuit) { _alertLayerWeight = 1; Animator.SetLayerWeight(Animator.GetLayerIndex("Alert Layer"), _alertLayerWeight); } else if (stateType == AIState.AIStateType.Feeding || stateType == AIState.AIStateType.Patrol || stateType == AIState.AIStateType.Idle) { _alertLayerWeight = 0; Animator.SetLayerWeight(Animator.GetLayerIndex("Alert Layer"), _alertLayerWeight); } _currentState.OnEnter(); } else { // If we don't find the state, we go into Idle. SwitchState(AIState.AIStateType.Idle); } }
private void Update() { if (!isServer) { return; } // Just for testing _targetName = ""; if (_currentTarget != null && _currentTarget.TargetTransform != null) { _targetName = _currentTarget.TargetTransform.name; } if (_currentState == null) { return; } if (!Health.IsAlive) { return; } AIState.AIStateType nextStateType = _currentState.OnUpdate(); if (nextStateType != _currentState.GetStateType()) { SwitchState(nextStateType); } }
public void SwitchState(AIState.AIStateType stateType) { if (_currentState != null) { _currentState.OnExit(); } if (_statesDictionary.TryGetValue(stateType, out _currentState)) { _currentState.OnEnter(); } else { // If we don't find the state, we go into Idle. SwitchState(AIState.AIStateType.Idle); } }
private void Update() { //Debug.Log(_currentState.GetStateType()); _target = _currentTarget; if (_currentState == null || _health.IsDead) { return; } AIState.AIStateType nextStateType = _currentState.OnUpdate(); if (nextStateType != _currentState.GetStateType()) { SwitchState(nextStateType); } }
public AIState GetState(AIState.AIStateType stateType) { return(_statesDictionary[stateType]); }