public override async Task Execute() { var scripts = Entity.Get<ScriptComponent>(); for (var index = 0; index < scripts.Scripts.Count; index++) { var script = scripts.Scripts[index]; var machineState = script as StateMachineState; if (machineState != null) { states.Add(machineState.GetType(), machineState); machineState.StateMachine = this; } } foreach (var stateMachineState in states) { stateMachineState.Value.Initialize(); } currentState = states.First().Value; currentState.Begin(null); while (Game.IsRunning) { if (currentState.ShouldEnd() && currentState.Next() != null) { var nextState = currentState.Next(); var prevState = currentState; currentState.End(nextState); currentState = nextState; currentState.Begin(prevState); } currentState.Update(); await Script.NextFrame(); } }
public override void Initialize() { animationComponent = Entity.Get<AnimationComponent>(); atkState = StateMachine.GetState(typeof(AttackState)); runState = StateMachine.GetState(typeof(RunState)); }
public abstract void End(StateMachineState nextState);
public abstract void Begin(StateMachineState previouState);
public override void End(StateMachineState nextState) { }
public override void Begin(StateMachineState previouState) { Shoot(); }
public override void Begin(StateMachineState previouState) { for (var index = 0; index < animationComponent.PlayingAnimations.Count; index++) { var animation = animationComponent.PlayingAnimations[index]; if (animation.Name == "Run") return; } animationComponent.Play("Run"); }
public override void Initialize() { animationComponent = Entity.Get<AnimationComponent>(); atkState = StateMachine.GetState(typeof(AttackState)); idlState = StateMachine.GetState(typeof(IdleState)); baseScaleX = Entity.Transform.Scale.X; }