MotionHandle.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. namespace LitMotion
  3. {
  4. /// <summary>
  5. /// An identifier that represents a specific motion entity.
  6. /// </summary>
  7. public struct MotionHandle : IEquatable<MotionHandle>
  8. {
  9. /// <summary>
  10. /// The ID of motion storage.
  11. /// </summary>
  12. public int StorageId;
  13. /// <summary>
  14. /// The ID of motion entity.
  15. /// </summary>
  16. public int Index;
  17. /// <summary>
  18. /// The generational version of motion entity.
  19. /// </summary>
  20. public int Version;
  21. /// <summary>
  22. /// Motion playback speed.
  23. /// </summary>
  24. public readonly float PlaybackSpeed
  25. {
  26. get
  27. {
  28. return MotionStorageManager.GetMotionDataRef(this).PlaybackSpeed;
  29. }
  30. set
  31. {
  32. if (value < 0f) Error.PlaybackSpeedMustBeZeroOrGreater();
  33. MotionStorageManager.GetMotionDataRef(this).PlaybackSpeed = value;
  34. }
  35. }
  36. public readonly bool Equals(MotionHandle other)
  37. {
  38. return Index == other.Index && Version == other.Version && StorageId == other.StorageId;
  39. }
  40. public override readonly bool Equals(object obj)
  41. {
  42. if (obj is MotionHandle handle) return Equals(handle);
  43. return false;
  44. }
  45. public override readonly int GetHashCode()
  46. {
  47. return HashCode.Combine(Index, Version, StorageId);
  48. }
  49. public static bool operator ==(MotionHandle a, MotionHandle b)
  50. {
  51. return a.Equals(b);
  52. }
  53. public static bool operator !=(MotionHandle a, MotionHandle b)
  54. {
  55. return !(a == b);
  56. }
  57. }
  58. }