Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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";
    }
Ejemplo n.º 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();
    }
Ejemplo n.º 4
0
    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;
    }
Ejemplo n.º 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());
            }
        }
    }
Ejemplo n.º 6
0
 public virtual void OnEnter()
 {
     Debug.Log("Entered: " + GetType());
     ChangeState = null;
 }
Ejemplo n.º 7
0
 void Start()
 {
     currentState = idleInactiveState;
     currentState.InitState(this);
 }
Ejemplo n.º 8
0
 private void ChangeState(ICharState newState)
 {
     _currentState?.OnExit();
     _currentState = newState;
     _currentState.OnEnter();
 }