mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:55:35 +00:00
44 lines
No EOL
992 B
C#
44 lines
No EOL
992 B
C#
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Cirno.Scripts.Components.FSM;
|
|
|
|
public partial class ActorStateMachine : CharacterBody2D
|
|
{
|
|
public Dictionary<int, State> States { get; private set; } = new();
|
|
|
|
private int _currentStateIndex = 0;
|
|
|
|
public State CurrentState => States[_currentStateIndex];
|
|
|
|
public override void _Ready()
|
|
{
|
|
var children = GetChildren();
|
|
|
|
foreach (var child in children)
|
|
{
|
|
if (child is State state)
|
|
{
|
|
States.Add(state.StateId, state);
|
|
state.Init(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetState(int stateId)
|
|
{
|
|
CurrentState.ExitState();
|
|
_currentStateIndex = stateId;
|
|
CurrentState.EnterState();
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
CurrentState.ProcessState(delta);
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
CurrentState.PhysicsProcessState(delta);
|
|
}
|
|
} |