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

68 行
1.4 KiB

using UOP1.StateMachine.ScriptableObjects;
namespace UOP1.StateMachine
{
public class State
{
internal StateSO _originSO;
internal StateMachine _stateMachine;
internal StateTransition[] _transitions;
internal StateAction[] _actions;
internal State() { }
public State(
StateSO originSO,
StateMachine stateMachine,
StateTransition[] transitions,
StateAction[] actions)
{
_originSO = originSO;
_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)
{
state = null;
for (int i = 0; i < _transitions.Length; i++)
if (_transitions[i].TryGetTransiton(out state))
break;
for (int i = 0; i < _transitions.Length; i++)
_transitions[i].ClearConditionsCache();
return state != null;
}
}
}