using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 状态模式的状态管理员基类,每一组状态的管理员都必须继承这个类
///
public class StateMachineBase : MonoBehaviour
{
protected StateBase currentState;
protected bool isBegin = false;
///
/// 改变状态的时候调用
///
///
public void ChangeState(StateBase newState)
{
isBegin = false;
if (currentState != null)
{
currentState.End();
}
currentState = newState;
}
///
/// 状态的每一帧调用,需要手动安排到主程序的Update中,切记!
///
public void StateUpdate()
{
if (currentState != null)
{
if (!isBegin)
{
currentState.Enter();
isBegin = true;
}
currentState.StateUpdate();
}
}
}