示例#1
0
 // Update is called once per frame
 void Update()
 {
     newState = currentState.DoState(this);
     if (currentState != newState)
     {
         //so if we DO change states. we will call Init,
         //then DoState will be called next frame. So dont have Init call DoState();
         currentState = newState;
         currentState.InitState(this);
     }
 }
示例#2
0
    void SwitchState()
    {
        stateIndex++;
        if (stateIndex >= charStates.Count)
            stateIndex = 0;

        currentState = charStates[stateIndex];
        if (currentState is LandState)
            spriteAnim.namePrefix = "grobo";
        else
            spriteAnim.namePrefix = "romaid";
    }
示例#3
0
    void Awake()
    {
        charStates.Add(new LandState());
        charStates.Add(new AquaticState());

        stateIndex = 0;
        currentState = charStates[stateIndex];
        sprite.spriteName = "grobo1";

        spawnSystem = GameObject.FindObjectOfType<CFX_SpawnSystem>();
        OnValidate();
    }
    public CharacterStateMachine(PlayerController player)
    {
        _player = player;
        CharacterState.Init(player);

        PlayerIdleState      idleState   = new PlayerIdleState();
        PlayerMoveState      moveState   = new PlayerMoveState();
        PlayerAimState       aimState    = new PlayerAimState();
        PlayerAttackingState attackState = new PlayerAttackingState();

        idleState.InitTransitions(moveState, aimState);
        moveState.InitTransitions(idleState, attackState, aimState);
        aimState.InitTransitions(moveState, attackState, idleState);
        attackState.InitTransitions(moveState);

        _allStates.Add(idleState.GetType(), idleState);
        _allStates.Add(moveState.GetType(), moveState);

        _currentState = idleState;
    }
示例#5
0
    public virtual void Update()
    {
        foreach (var transition in _transitionToStates)
        {
            if (transition.GetType() == typeof(PlayerIdleState))
            {
                idleState = transition;
            }

            Func <bool> Condition;
            if (transition.TransitionConditions.TryGetValue(GetType(), out Condition))
            {
                if (Condition())
                {
                    ChangeState = transition;
                    return;
                }
            }
            else
            {
                Debug.LogError("Transition Condition Doesn't exit for: " + GetType() + " to " + transition.GetType());
            }
        }
    }
示例#6
0
 public virtual void OnEnter()
 {
     Debug.Log("Entered: " + GetType());
     ChangeState = null;
 }
示例#7
0
 void Start()
 {
     currentState = idleInactiveState;
     currentState.InitState(this);
 }
 private void ChangeState(ICharState newState)
 {
     _currentState?.OnExit();
     _currentState = newState;
     _currentState.OnEnter();
 }