2025-06-10 13:16:36 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
[Tool]
|
|
|
|
[GlobalClass ]
|
|
|
|
public partial class TweenPosition:SequenceAction
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public Node3D target;
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
[Export]
|
|
|
|
public Mode positionSpace = Mode.Global;
|
|
|
|
|
2025-06-10 13:16:36 +00:00
|
|
|
[Export]
|
|
|
|
public Node3D endPosition;
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
public enum Mode
|
|
|
|
{
|
|
|
|
Global,
|
|
|
|
Local
|
|
|
|
}
|
|
|
|
|
2025-06-10 13:16:36 +00:00
|
|
|
[Export]
|
|
|
|
public Vector3 endOffset;
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
|
|
|
|
|
2025-06-10 13:16:36 +00:00
|
|
|
[Export]
|
|
|
|
public TweenType tweenType = new TweenTimeCurve();
|
|
|
|
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
|
|
|
|
|
2025-06-10 13:16:36 +00:00
|
|
|
[Export]
|
|
|
|
public bool cacheEndPositionOnStart = true;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public TimeLine timeLine;
|
|
|
|
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
Vector3 GetToPosition()
|
|
|
|
{
|
|
|
|
var toPosition = endOffset;
|
|
|
|
|
|
|
|
if ( Mode.Global == positionSpace )
|
|
|
|
{
|
|
|
|
if ( endPosition != null )
|
|
|
|
{
|
|
|
|
toPosition += endPosition.GlobalPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( endPosition != null )
|
|
|
|
{
|
|
|
|
toPosition += endPosition.Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return toPosition;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-06-10 13:16:36 +00:00
|
|
|
protected override void _OnTrigger()
|
|
|
|
{
|
|
|
|
if ( target == null )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tl = TimeLineManager.Ensure( timeLine );
|
|
|
|
|
|
|
|
var start = tl.position;
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
var fromPosition = target.GetPosition( Mode.Global == positionSpace );
|
|
|
|
var toPosition = GetToPosition();
|
2025-06-10 13:16:36 +00:00
|
|
|
|
|
|
|
var sequenceID = DispatchStart();
|
|
|
|
|
|
|
|
var tweenType = this.tweenType;
|
|
|
|
|
|
|
|
if ( tweenType == null )
|
|
|
|
{
|
|
|
|
tweenType = TweenTimeCurve.defaultCurve;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeLineManager.ScheduleSpanIn( tl, 0, tweenType.GetTweenDuration(),
|
|
|
|
( span, type )=>
|
|
|
|
{
|
|
|
|
var timeNow = tl.position;
|
|
|
|
var elapsed = timeNow - start;
|
|
|
|
|
|
|
|
var state = tweenType.GetTweenPhaseForPhase( span.phase );
|
|
|
|
|
|
|
|
if ( ! cacheEndPositionOnStart )
|
|
|
|
{
|
2025-06-19 17:22:25 +00:00
|
|
|
toPosition = GetToPosition();
|
2025-06-10 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var lerpedPosition = fromPosition.Lerp( toPosition, state );
|
|
|
|
|
2025-06-19 17:22:25 +00:00
|
|
|
if ( Mode.Global == positionSpace )
|
|
|
|
{
|
|
|
|
target.GlobalPosition = lerpedPosition;
|
|
|
|
}
|
|
|
|
else if ( Mode.Local == positionSpace )
|
|
|
|
{
|
|
|
|
target.Position = lerpedPosition;
|
|
|
|
}
|
|
|
|
|
2025-06-10 13:16:36 +00:00
|
|
|
if ( type == TimeLineSpanUpdateType.End )
|
|
|
|
{
|
|
|
|
DispatchEnd( sequenceID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|