Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WithStartTime and GetTime to allow toggle behaviour #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal unsafe interface IMotionStorage
void Cancel(MotionHandle handle);
void Complete(MotionHandle handle);
float GetPlaybackSpeed(MotionHandle handle);
double GetTime(MotionHandle handle);
void SetPlaybackSpeed(MotionHandle handle, float value);
MotionCallbackData GetMotionCallbacks(MotionHandle handle);
void SetMotionCallbacks(MotionHandle handle, MotionCallbackData callbacks);
Expand Down Expand Up @@ -386,6 +387,12 @@ public float GetPlaybackSpeed(MotionHandle handle)
return dataArray[entries[handle.Index].DenseIndex].PlaybackSpeed;
}

public double GetTime(MotionHandle handle)
{
CheckIndex(handle);
return dataArray[entries[handle.Index].DenseIndex].Time;
}

public void SetPlaybackSpeed(MotionHandle handle, float value)
{
CheckIndex(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public static float GetMotionPlaybackSpeed(MotionHandle handle)
return storageList[handle.StorageId].GetPlaybackSpeed(handle);
}

public static double GetMotionTime(MotionHandle handle)
{
CheckStorageId(handle);
return storageList[handle.StorageId].GetTime(handle);
}

public static void SetMotionPlaybackSpeed(MotionHandle handle, float value)
{
if (value < 0f) throw new ArgumentOutOfRangeException("Playback speed must be 0 or greater.");
Expand Down
16 changes: 16 additions & 0 deletions src/LitMotion/Assets/LitMotion/Runtime/MotionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static void Return(MotionBuilderBuffer<TValue, TOptions> buffer)
{
buffer.Version++;
buffer.Duration = default;
buffer.StartTime = default;
buffer.Ease = default;
buffer.Delay = default;
buffer.DelayType = default;
Expand All @@ -55,6 +56,7 @@ public static void Return(MotionBuilderBuffer<TValue, TOptions> buffer)
public MotionBuilderBuffer<TValue, TOptions> NextNode;

public float Duration;
public double StartTime;
public Ease Ease;
public float Delay;
public DelayType DelayType;
Expand Down Expand Up @@ -107,6 +109,19 @@ public readonly MotionBuilder<TValue, TOptions, TAdapter> WithEase(Ease ease)
return this;
}

/// <summary>
/// Specify start time
/// </summary>
/// <param name="ease">The start time</param>
/// <returns>This builder to allow chaining multiple method calls.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly MotionBuilder<TValue, TOptions, TAdapter> WithStartTime(double time)
{
CheckBuffer();
buffer.StartTime = time;
return this;
}

/// <summary>
/// Specify the delay time when the motion starts.
/// </summary>
Expand Down Expand Up @@ -358,6 +373,7 @@ internal MotionData<TValue, TOptions> BuildMotionData()
StartValue = buffer.StartValue,
EndValue = buffer.EndValue,
Options = buffer.Options,
Time = buffer.StartTime,
Duration = buffer.Duration,
PlaybackSpeed = 1f,
Ease = buffer.Ease,
Expand Down
5 changes: 5 additions & 0 deletions src/LitMotion/Assets/LitMotion/Runtime/MotionHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public readonly float PlaybackSpeed
set => MotionStorageManager.SetMotionPlaybackSpeed(this, value);
}

public readonly double Time
{
get => MotionStorageManager.GetMotionTime(this);
}

public readonly bool Equals(MotionHandle other)
{
return Index == other.Index && Version == other.Version && StorageId == other.StorageId;
Expand Down