using UnityEngine; using UnityEditor.Timeline; using UnityEngine.Playables; 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; } public override bool Equals(object obj) { if (!(obj is MarkerDrawOptions)) return false; return Equals((MarkerDrawOptions)obj); } public bool Equals(MarkerDrawOptions other) { return errorText == other.errorText && tooltip == other.tooltip; } public override int GetHashCode() { return HashUtility.CombineHash( errorText != null ? errorText.GetHashCode() : 0, tooltip != null ? tooltip.GetHashCode() : 0 ); } public static bool operator==(MarkerDrawOptions options1, MarkerDrawOptions options2) { return options1.Equals(options2); } 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; } /// /// TThe area where the overlay is being drawn. /// public Rect timelineRegion { get; private set; } /// /// 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; } /// Constructor public MarkerOverlayRegion(Rect _markerRegion, Rect _timelineRegion, double _startTime, double _endTime) { markerRegion = _markerRegion; timelineRegion = _timelineRegion; startTime = _startTime; endTime = _endTime; } public override bool Equals(object obj) { if (!(obj is MarkerOverlayRegion)) return false; return Equals((MarkerOverlayRegion)obj); } public bool Equals(MarkerOverlayRegion other) { return markerRegion == other.markerRegion && timelineRegion == other.timelineRegion && startTime == other.startTime && endTime == other.endTime; } public override int GetHashCode() { return HashUtility.CombineHash( markerRegion.GetHashCode(), timelineRegion.GetHashCode(), startTime.GetHashCode(), endTime.GetHashCode() ); } public static bool operator==(MarkerOverlayRegion region1, MarkerOverlayRegion region2) { return region1.Equals(region2); } 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) { } } }