36 lines
906 B
C#
36 lines
906 B
C#
using Engine.Core;
|
|
using Engine.Systems.Tween;
|
|
|
|
namespace MyUniverse.Shared.Behaviours;
|
|
|
|
public class TweenRotator : Behaviour2D, IRotator, IFirstFrameUpdate, ILastFrameUpdate
|
|
{
|
|
private float duration = 5f;
|
|
private float angle = 180;
|
|
private IEasing easeMethod = EaseInOutQuad.Instance;
|
|
private ITweenManager tweenManager = null!;
|
|
private ITween tween = null!;
|
|
|
|
public void FirstActiveFrame()
|
|
{
|
|
tweenManager = Universe.FindRequiredBehaviour<ITweenManager>();
|
|
|
|
TweenRotation();
|
|
}
|
|
|
|
private void TweenRotation()
|
|
{
|
|
if (Transform.Rotation >= 360f)
|
|
Transform.Rotation -= 360f;
|
|
|
|
tween = Transform.TweenRotation(tweenManager, duration, Transform.Rotation + angle)
|
|
.Ease(easeMethod)
|
|
.OnComplete(TweenRotation);
|
|
}
|
|
|
|
public void LastActiveFrame()
|
|
{
|
|
tweenManager.CancelTween(tween);
|
|
}
|
|
}
|