using System; namespace LitMotion { /// /// An identifier that represents a specific motion entity. /// public struct MotionHandle : IEquatable { /// /// Represents an empty MotionHandle. This is the same as default(MotionHandle). /// public static readonly MotionHandle None = default; /// /// The ID of motion storage. /// public int StorageId; /// /// The ID of motion entity. /// public int Index; /// /// The generational version of motion entity. /// public int Version; /// /// Motion time /// public readonly double Time { get { return MotionManager.GetDataRef(this, false).State.Time; } set { MotionManager.SetTime(this, value); } } /// /// The delay of the motion /// public readonly float Delay { get { return MotionManager.GetDataRef(this, false).Parameters.Delay; } } /// /// The duration of the motion /// public readonly float Duration { get { return MotionManager.GetDataRef(this, false).Parameters.Duration; } } /// /// The total duration of the motion /// public readonly double TotalDuration { get { return MotionManager.GetDataRef(this, false).Parameters.TotalDuration; } } /// /// The number of loops /// public readonly int Loops { get { return MotionManager.GetDataRef(this, false).Parameters.Loops; } } /// /// The number of loops completed /// public readonly int CompletedLoops { get { return MotionManager.GetDataRef(this).State.CompletedLoops; } } /// /// Motion playback speed. /// public readonly float PlaybackSpeed { get { return MotionManager.GetDataRef(this).State.PlaybackSpeed; } set { MotionManager.GetDataRef(this).State.PlaybackSpeed = value; } } public override readonly string ToString() { return $"MotionHandle`{StorageId} ({Index}:{Version})"; } public readonly bool Equals(MotionHandle other) { return Index == other.Index && Version == other.Version && StorageId == other.StorageId; } public override readonly bool Equals(object obj) { if (obj is MotionHandle handle) return Equals(handle); return false; } public override readonly int GetHashCode() { return HashCode.Combine(Index, Version, StorageId); } public static bool operator ==(MotionHandle a, MotionHandle b) { return a.Equals(b); } public static bool operator !=(MotionHandle a, MotionHandle b) { return !(a == b); } } }