This commit is contained in:
陈思海 2025-09-10 16:06:07 +08:00
parent 7157a9fa25
commit 908d3e41f2

View File

@ -215,38 +215,42 @@ namespace AlicizaX.Fsm
{
if (_disposed) return;
bool flag = false;
if (!Initialized)
{
Reset(Current);
goto EDITOR_TRACK;
flag = true;
}
TimeInState += deltaTime;
if (!flag)
{
TimeInState += deltaTime;
// 1) state internal update (may suggest next state)
int suggested = _funcs[Current].OnUpdate(_bb);
if (suggested >= 0 && suggested != Current)
{
ChangeState(suggested);
}
else
{
// 2) transitions (timeout first, then condition)
ref readonly TransitionIndex ti = ref _index[Current];
for (int i = 0; i < ti.Length; i++)
// 1) state internal update (may suggest next state)
int suggested = _funcs[Current].OnUpdate(_bb);
if (suggested >= 0 && suggested != Current)
{
ref readonly var tr = ref _trans[ti.Start + i];
bool timeoutOk = (tr.Timeout > 0f && TimeInState >= tr.Timeout);
bool condOk = (!timeoutOk && tr.Cond != null && tr.Cond(_bb));
if (timeoutOk || condOk)
ChangeState(suggested);
}
else
{
// 2) transitions (timeout first, then condition)
ref readonly TransitionIndex ti = ref _index[Current];
for (int i = 0; i < ti.Length; i++)
{
ChangeState(tr.To);
break;
ref readonly var tr = ref _trans[ti.Start + i];
bool timeoutOk = (tr.Timeout > 0f && TimeInState >= tr.Timeout);
bool condOk = (!timeoutOk && tr.Cond != null && tr.Cond(_bb));
if (timeoutOk || condOk)
{
ChangeState(tr.To);
break;
}
}
}
}
EDITOR_TRACK:
#if UNITY_EDITOR
if (FSMDebugger.Enabled)
FSMDebugger.Track(this);