Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/LitMotion/Assets/LitMotion/Runtime/MotionSequenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static void Return(MotionSequenceBuilderSource source)
MotionSequenceBuilderSource next;
ushort version;
MotionSequenceItem[] buffer;
Ease ease;
int count;
double tail;
double lastTail;
Expand Down Expand Up @@ -70,10 +71,16 @@ public void Join(MotionHandle handle)
Insert(lastTail, handle);
}

public void WithEase(Ease ease)
{
this.ease = ease;
}

public MotionHandle Schedule(Action<MotionBuilder<double, NoOptions, DoubleMotionAdapter>> configuration)
{
var source = MotionSequenceSource.Rent();
var builder = LMotion.Create(0.0, duration, (float)duration)
.WithEase(ease)
.WithOnComplete(source.OnCompleteDelegate)
.WithOnCancel(source.OnCancelDelegate);

Expand Down Expand Up @@ -148,6 +155,14 @@ public readonly MotionSequenceBuilder Join(MotionHandle handle)
return this;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly MotionSequenceBuilder WithEase(Ease ease)
{
CheckIsDisposed();
source.WithEase(ease);
return this;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MotionHandle Run()
{
Expand Down
36 changes: 36 additions & 0 deletions src/LitMotion/Assets/LitMotion/Tests/Runtime/SequenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,41 @@ public void Test_Error_UseMotionHandleInSequence()
handle.Time = 0;
}, "Cannot access the motion in sequence.");
}

[UnityTest]
public IEnumerator Test_SequenceWithEase()
{
var x1 = 0f;
var x2 = 0f;
Ease ease = Ease.InExpo;

var motionHandle = LSequence.Create()
.Append(LMotion.Create(0f, 1f, 5f).Bind(v => x1 = v))
.Append(LMotion.Create(0f, 1f, 5f).Bind(v => x2 = v))
.WithEase(ease)
.Run();

motionHandle.Preserve();

for (int i = 1; i <= 10; i++)
{
yield return new WaitForSeconds(1f);
float sequenceProgress = (float)motionHandle.Time / 10f;
float sequenceEasedTime = EaseUtility.Evaluate(sequenceProgress, ease);
Assert.AreEqual(GetX1Time(sequenceEasedTime), x1, 0.01f, $"iteration: {i}");
Assert.AreEqual(GetX2Time(sequenceEasedTime), x2, 0.01f, $"iteration: {i}");
}
yield break;

float GetX1Time(float time)
{
return Mathf.Clamp01(time / 0.5f);
}

float GetX2Time(float time)
{
return Mathf.Clamp01((time - 0.5f) / 0.5f);
}
}
}
}