您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
61 行
1.2 KiB
61 行
1.2 KiB
namespace UOP1.StateMachine
|
|
{
|
|
public class State
|
|
{
|
|
public string Name { get; internal set; }
|
|
|
|
internal StateMachine _stateMachine;
|
|
internal StateTransition[] _transitions;
|
|
internal StateAction[] _actions;
|
|
|
|
internal State() { }
|
|
|
|
public State(
|
|
StateMachine stateMachine,
|
|
StateTransition[] transitions,
|
|
StateAction[] actions)
|
|
{
|
|
_stateMachine = stateMachine;
|
|
_transitions = transitions;
|
|
_actions = actions;
|
|
}
|
|
|
|
public void OnStateEnter()
|
|
{
|
|
void OnStateEnter(IStateComponent[] comps)
|
|
{
|
|
for (int i = 0; i < comps.Length; i++)
|
|
comps[i].OnStateEnter();
|
|
}
|
|
OnStateEnter(_transitions);
|
|
OnStateEnter(_actions);
|
|
}
|
|
|
|
public void OnUpdate()
|
|
{
|
|
for (int i = 0; i < _actions.Length; i++)
|
|
_actions[i].OnUpdate();
|
|
}
|
|
|
|
public void OnStateExit()
|
|
{
|
|
void OnStateExit(IStateComponent[] comps)
|
|
{
|
|
for (int i = 0; i < comps.Length; i++)
|
|
comps[i].OnStateExit();
|
|
}
|
|
OnStateExit(_transitions);
|
|
OnStateExit(_actions);
|
|
}
|
|
|
|
public bool TryGetTransition(out State state)
|
|
{
|
|
for (int i = 0; i < _transitions.Length; i++)
|
|
if (_transitions[i].TryGetTransiton(out state))
|
|
return true;
|
|
|
|
state = null;
|
|
return false;
|
|
}
|
|
}
|
|
}
|