//#define STATEMACHINE_DEBUG
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StateController<T> : MonoBehaviour where T : BaseState {

    protected T currentState;

    public void ChangeState(T newState) {
#if STATEMACHINE_DEBUG
        Debug.Log ("[State Controller] Setting new state: " + newState);
#endif

        if (this.currentState != null) {
            this.PrepareStateForDeinit(this.currentState);
            this.currentState.DeinitState();
        }

        this.currentState = newState;

        if (this.currentState != null) {
            this.PrepareStateForInit(this.currentState);
            this.currentState.InitState();
        }

    }

    protected virtual void Update () {
        if (this.currentState != null) {
            this.currentState.UpdateState();
        }
    }

    protected virtual void PrepareStateForDeinit (T state) {
        
    }

    protected virtual void PrepareStateForInit (T state) {

    }
}
