维基百科:有限状态机(英语:finite-state machine,缩写:FSM)又称有限状态自动机,简称状态机,是表示有限个状态以及在这些状态之间的转移和动作等行为的数学模型。
本文参照quick-cocos中的StateMachine, 实现了Unity版本的有限状态机。
实现思路:
- 创建一个状态机对象
public class StateMachine : MonoBehaviour {
...
}
- 初始化状态机信息,包括事件和回调函数。
// 事件
public class SMEvent
{
readonly string name;
readonly List<string> froms;
readonly string to;
public string Name { get { return name; } }
public List<string> Froms { get { return froms; } }
public string To { get { return to; } }
public SMEvent(string _name, List<str