这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

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;
}
}
}