You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
using System;
|
|
using UnityEngine;
|
|
|
|
public class MerchantMove : State<Character>
|
|
{
|
|
Transform start;
|
|
Transform destination;
|
|
float duration;
|
|
Func<float> getCurrentElapsedTime;
|
|
|
|
public bool HasDestination => destination != null;
|
|
|
|
public void Setup(Transform start, Transform destination, float duration, Func<float> getCurrentElapsedTime)
|
|
{
|
|
Debug.Assert(start != null && destination != null && duration > 0, "arguments are not valid");
|
|
|
|
this.start = start;
|
|
this.destination = destination;
|
|
this.duration = duration;
|
|
this.getCurrentElapsedTime = getCurrentElapsedTime;
|
|
}
|
|
|
|
public override void Enter()
|
|
{
|
|
Debug.Assert(Owner.Excutor.SkeletonAnimation.TryGetAnimation("move", out Spine.Animation _), "move animation not exist");
|
|
Owner.Excutor.SkeletonAnimation.AnimationState.SetAnimation(0, "move", true);
|
|
}
|
|
|
|
public override void Excute()
|
|
{
|
|
float elapsedTime = getCurrentElapsedTime();
|
|
|
|
if (elapsedTime >= duration)
|
|
{
|
|
Owner.ChangeState<MerchantIdle>();
|
|
}
|
|
else
|
|
{
|
|
Owner.Excutor.Position = Vector2.Lerp(start.position, destination.position, elapsedTime / duration);
|
|
}
|
|
}
|
|
|
|
public override void Exit()
|
|
{
|
|
start = null;
|
|
destination = null;
|
|
duration = 0;
|
|
}
|
|
}
|