using UnityEngine; using UnityEngine.Timeline; namespace UnityEditor.Timeline { /// /// The flags that indicate the view status of a marker. /// [System.Flags] public enum MarkerUIStates { /// /// No extra state specified. /// None = 0, /// /// The marker is selected. /// Selected = 1 << 0, /// /// The marker is in a collapsed state. /// Collapsed = 1 << 1 } /// /// The user-defined options for drawing a marker. /// public struct MarkerDrawOptions { /// /// The tooltip for the marker. /// public string tooltip { get; set; } /// /// Text that indicates if the marker should display an error. /// /// /// If the error text is not empty or null, then the marker displays a warning. The error text is used as the tooltip. /// public string errorText { get; set; } /// /// Indicates whether this instance and a specified object are equal. /// /// The object to compare with the current instance. /// Returns true if and this instance are the same type and represent the same value. public override bool Equals(object obj) { if (!(obj is MarkerDrawOptions)) return false; return Equals((MarkerDrawOptions)obj); } /// /// Compares this object with another MarkerDrawOptions. /// /// The object to compare with. /// Returns true if this and are equal. public bool Equals(MarkerDrawOptions other) { return errorText == other.errorText && tooltip == other.tooltip; } /// /// Returns the hash code for this instance. /// /// A 32-bit signed integer that is the hash code for this instance. public override int GetHashCode() { return HashUtility.CombineHash( errorText != null ? errorText.GetHashCode() : 0, tooltip != null ? tooltip.GetHashCode() : 0 ); } /// /// Compares two MarkerDrawOptions objects. /// /// The first object. /// The second object. /// Returns true if they are equal. public static bool operator ==(MarkerDrawOptions options1, MarkerDrawOptions options2) { return options1.Equals(options2); } /// /// Compares two MarkerDrawOptions objects. /// /// The first object. /// The second object. /// Returns true if they are not equal. public static bool operator !=(MarkerDrawOptions options1, MarkerDrawOptions options2) { return !options1.Equals(options2); } } /// /// The description of the on-screen area where the marker is drawn. /// public struct MarkerOverlayRegion { /// /// The area where the marker is being drawn. /// public Rect markerRegion { get; private set; } /// /// The area where the overlay is being drawn. /// /// This region extends from the top of the time ruler to the bottom of the window, excluding any scrollbars. /// public Rect timelineRegion { get; private set; } /// /// The sub-area of the timelineRegion where the tracks are drawn. /// /// The region extends from the bottom of the time ruler, or the timeline marker region if not hidden. /// Use this region to clip overlays that should not be drawn over the timeline marker region or time ruler. /// /// /// /// public Rect trackRegion => Rect.MinMaxRect(timelineRegion.xMin, timelineRegion.yMin + m_TrackOffset, timelineRegion.xMax, timelineRegion.yMax); /// /// The start time of the visible region of the window. /// public double startTime { get; private set; } /// /// The end time of the visible region of the window. /// public double endTime { get; private set; } private float m_TrackOffset; /// Constructor /// The area where the marker is being drawn. /// The area where the overlay is being drawn. /// The start time of the visible region of the window. /// The end time of the visible region of the window. public MarkerOverlayRegion(Rect _markerRegion, Rect _timelineRegion, double _startTime, double _endTime) : this(_markerRegion, _timelineRegion, _startTime, _endTime, 19.0f) { } /// Constructor /// The area where the marker is being drawn. /// The area where the overlay is being drawn. /// The start time of the visible region of the window. /// The end time of the visible region of the window. /// The offset from the timelineRegion to the trackRegion public MarkerOverlayRegion(Rect _markerRegion, Rect _timelineRegion, double _startTime, double _endTime, float _trackOffset) { markerRegion = _markerRegion; timelineRegion = _timelineRegion; startTime = _startTime; endTime = _endTime; m_TrackOffset = _trackOffset; } /// /// Indicates whether this instance and a specified object are equal. /// /// The object to compare with the current instance. /// Returns true if and this instance are the same type and represent the same value. public override bool Equals(object obj) { if (!(obj is MarkerOverlayRegion)) return false; return Equals((MarkerOverlayRegion)obj); } /// /// Compares this object with another MarkerOverlayRegion. /// /// The object to compare with. /// Returns true if this and are equal. public bool Equals(MarkerOverlayRegion other) { return markerRegion == other.markerRegion && timelineRegion == other.timelineRegion && startTime == other.startTime && endTime == other.endTime && m_TrackOffset == other.m_TrackOffset; } /// /// Returns the hash code for this instance. /// /// A 32-bit signed integer that is the hash code for this instance. public override int GetHashCode() { return HashUtility.CombineHash( markerRegion.GetHashCode(), timelineRegion.GetHashCode(), startTime.GetHashCode(), endTime.GetHashCode(), m_TrackOffset.GetHashCode() ); } /// /// Compares two MarkerOverlayRegion objects. /// /// The first object. /// The second object. /// Returns true if they are equal. public static bool operator ==(MarkerOverlayRegion region1, MarkerOverlayRegion region2) { return region1.Equals(region2); } /// /// Compares two MarkerOverlayRegion objects. /// /// The first object. /// The second object. /// Returns true if they are not equal. public static bool operator !=(MarkerOverlayRegion region1, MarkerOverlayRegion region2) { return !region1.Equals(region2); } } /// /// Use this class to customize marker types in the TimelineEditor. /// public class MarkerEditor { internal readonly bool supportsDrawOverlay; /// /// Default constructor /// public MarkerEditor() { supportsDrawOverlay = TypeUtility.HasOverrideMethod(GetType(), nameof(DrawOverlay)); } /// /// Implement this method to override the default options for drawing a marker. /// /// The marker to draw. /// public virtual MarkerDrawOptions GetMarkerOptions(IMarker marker) { return new MarkerDrawOptions() { tooltip = string.Empty, errorText = string.Empty, }; } /// /// Called when a marker is created. /// /// The marker that is created. /// TThe source that the marker was copied from. This can be set to null if the marker is not a copy. /// /// The callback occurs before the marker is assigned to the track. /// public virtual void OnCreate(IMarker marker, IMarker clonedFrom) { } /// /// Draws additional overlays for a marker. /// /// The marker to draw. /// The visual state of the marker. /// The on-screen area where the marker is being drawn. /// /// Notes: /// * It is only called during TimelineWindow's Repaint step. /// * If there are multiple markers on top of each other, only the topmost marker receives the DrawOverlay call. /// public virtual void DrawOverlay(IMarker marker, MarkerUIStates uiState, MarkerOverlayRegion region) { } } }