暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SequenceContext.cs 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using UnityEngine.Playables;
  3. using UnityEngine.Timeline;
  4. namespace UnityEditor.Timeline
  5. {
  6. /// <summary>
  7. /// A context for the Timeline window (RO)
  8. /// </summary>
  9. /// <remarks>
  10. /// The SequenceContext represents a state of the Timeline window, and is used to interact with <see cref="TimelineNavigator"/>.
  11. /// </remarks>
  12. public readonly struct SequenceContext : IEquatable<SequenceContext>
  13. {
  14. /// <summary>
  15. /// The director associated with the Timeline window in the context. (RO)
  16. /// </summary>
  17. public PlayableDirector director { get; }
  18. /// <summary>
  19. /// The <see cref="TimelineClip"/> associated with the Timeline window in the context. (RO)
  20. /// </summary>
  21. /// <remarks>In a SubTimeline context, the clip is the <see cref="TimelineClip"/> that hosts the SubTimeline in the parent Timeline.
  22. /// In the root context, the clip is <see langword="null"/>.</remarks>
  23. public TimelineClip clip { get; }
  24. /// <summary>
  25. /// Initializes and returns an instance of SequenceContext.
  26. /// </summary>
  27. /// <param name="director">The PlayableDirector associated with the context. Must be a valid PlayableDirector reference. </param>
  28. /// <param name="clip">The TimelineClip reference that controls the sequence. Specify <see langword="null"/> to specify that the sequence is the root. If non-null, the clip must be part of a valid <see cref="TimelineAsset"/>.</param>
  29. /// <exception cref="System.ArgumentNullException"> <paramref name="director"/> is null.</exception>
  30. /// <exception cref="System.ArgumentException"> The <paramref name="clip"/> is not part of a <see cref="TrackAsset"/>.</exception>
  31. /// <exception cref="System.ArgumentException"> The <paramref name="clip"/> is part of a track but not part of a <see cref="TimelineAsset"/>.</exception>
  32. public SequenceContext(PlayableDirector director, TimelineClip clip)
  33. {
  34. if (director == null)
  35. throw new ArgumentNullException(nameof(director));
  36. var parentTrack = clip?.GetParentTrack();
  37. if (clip != null && parentTrack == null)
  38. throw new ArgumentException("The provided clip must be part of a track", nameof(clip));
  39. if (clip != null && parentTrack.timelineAsset == null)
  40. throw new ArgumentException("The provided clip must be part of a Timeline.", nameof(clip));
  41. this.director = director;
  42. this.clip = clip;
  43. m_Valid = true;
  44. }
  45. /// <summary>
  46. /// Assesses the validity of a SequenceContext.
  47. /// </summary>
  48. /// <remarks>To be valid, a SequenceContext must contain a valid PlayableDirector reference.</remarks>
  49. /// <returns><see langword="true" /> if the SequenceContext is valid,<see langword="false" /> otherwise</returns>
  50. public bool IsValid() => m_Valid;
  51. /// <summary>
  52. /// Equality operator overload.
  53. /// </summary>
  54. /// <param name="left"></param>
  55. /// <param name="right"></param>
  56. /// <returns><see langword="true" /> if operands are equal, <see langword="false" /> otherwise.</returns>
  57. public static bool operator ==(SequenceContext left, SequenceContext right) => left.Equals(right);
  58. /// <summary>
  59. /// Inequality operator overload.
  60. /// </summary>
  61. /// <param name="left"></param>
  62. /// <param name="right"></param>
  63. /// <returns><see langword="true" /> if operands are not equal, <see langword="false" /> otherwise.</returns>
  64. public static bool operator !=(SequenceContext left, SequenceContext right) => !left.Equals(right);
  65. /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
  66. /// <param name="other">An object to compare with this object.</param>
  67. /// <returns>
  68. /// <see langword="true" /> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false" />.</returns>
  69. public bool Equals(SequenceContext other)
  70. {
  71. return Equals(director, other.director) && Equals(clip, other.clip);
  72. }
  73. /// <summary>Indicates whether the current object is equal to another object of indeterminate type.</summary>
  74. /// <param name="obj">An object to compare with this object.</param>
  75. /// <returns>
  76. /// <see langword="true" /> if the current object is equal to the <paramref name="obj" /> parameter; otherwise, <see langword="false" />.</returns>
  77. public override bool Equals(object obj)
  78. {
  79. return obj is SequenceContext other && Equals(other);
  80. }
  81. /// <summary>Hash function for SequenceContext.</summary>
  82. /// <returns>
  83. /// Hash code for the SequenceContext.
  84. /// </returns>
  85. public override int GetHashCode()
  86. {
  87. unchecked
  88. {
  89. return ((director != null ? director.GetHashCode() : 0) * 397) ^ (clip != null ? clip.GetHashCode() : 0);
  90. }
  91. }
  92. internal static SequenceContext Invalid = new SequenceContext();
  93. readonly bool m_Valid;
  94. }
  95. }