66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using Intrepid.Structures;
|
|
using Intrepid.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace Intrepid.Gameplay.Entities.Sentinel.StateMachine.States
|
|
{
|
|
public class SentinelStateDashBreaking : SentinelState
|
|
{
|
|
[GroupConfigurations, SerializeField] private AnimationClip dashBreaking;
|
|
[GroupConfigurations, SerializeField, Range(5, 30)] private float speed = 10;
|
|
[GroupConfigurations, SerializeField, Range(0, 500)] private float extraTimeMS = 300f;
|
|
[GroupConfigurations, SerializeField] private AnimationCurve speedCurve;
|
|
|
|
private Timer Timer { get; } = new();
|
|
private float ExtraTime => extraTimeMS * 0.001f;
|
|
|
|
public override SentinelStateType GetStateKey()
|
|
{
|
|
return SentinelStateType.DashBreaking;
|
|
}
|
|
|
|
protected override void Subscriptions()
|
|
{
|
|
}
|
|
|
|
protected override void RunOnEnter(ParameterStore parameterStore)
|
|
{
|
|
Brain.Controls.ResetDash();
|
|
Brain.Entity.ModelAnimation.Play(dashBreaking);
|
|
Timer.Stop();
|
|
}
|
|
|
|
protected override void RunOnExit()
|
|
{
|
|
Brain.Entity.DesiredVelocity = Vector2.zero;
|
|
Timer.Stop();
|
|
}
|
|
|
|
public override void RunOnUpdate()
|
|
{
|
|
if (Brain.Entity.ModelAnimation.IsFinished)
|
|
{
|
|
if (Timer.IsNotRunning)
|
|
{
|
|
Brain.Entity.DesiredVelocity = Vector2.zero;
|
|
Timer.Start();
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Brain.Entity.DesiredVelocity = Brain.Entity.Forward * speed;
|
|
}
|
|
|
|
if (Timer.IsNotRunning) return;
|
|
Timer.Update(Time.deltaTime);
|
|
var evaluation = speedCurve.Evaluate((float) Timer.ElapsedTime / ExtraTime);
|
|
Brain.Entity.DesiredVelocity = Brain.Entity.Forward * (speed * evaluation);
|
|
if (Timer.Check(ExtraTime))
|
|
{
|
|
Timer.Stop();
|
|
Brain.ChangeState(SentinelStateType.Idle);
|
|
}
|
|
}
|
|
}
|
|
} |