예제 #1
0
    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);
        }
    }
예제 #2
0
    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);
        }
    }
예제 #3
0
    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);
        }
    }
예제 #4
0
    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);
        }
    }
예제 #5
0
 public AIState GetState(AIState.AIStateType stateType)
 {
     return(_statesDictionary[stateType]);
 }