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