initial commit
This commit is contained in:
35
Shared/Behaviours/TweenRotator.cs
Normal file
35
Shared/Behaviours/TweenRotator.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user