From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../Editor/CustomEditors/ClipEditor.cs | 256 +++++++++++++++++++ .../Editor/CustomEditors/ClipEditor.cs.meta | 11 + .../CustomEditors/CustomTimelineEditorCache.cs | 155 +++++++++++ .../CustomTimelineEditorCache.cs.meta | 11 + .../Editor/CustomEditors/MarkerEditor.cs | 209 +++++++++++++++ .../Editor/CustomEditors/MarkerEditor.cs.meta | 11 + .../Editor/CustomEditors/MarkerTrackEditor.cs | 18 ++ .../Editor/CustomEditors/MarkerTrackEditor.cs.meta | 11 + .../Editor/CustomEditors/TrackEditor.cs | 284 +++++++++++++++++++++ .../Editor/CustomEditors/TrackEditor.cs.meta | 11 + 10 files changed, 977 insertions(+) create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs.meta create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs.meta create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs.meta create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs.meta create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs.meta (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors') diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs new file mode 100644 index 0000000..9f133a1 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs @@ -0,0 +1,256 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Playables; +using UnityEngine.Timeline; + +namespace UnityEditor.Timeline +{ + /// + /// Description of the on-screen area where a clip is drawn + /// + public struct ClipBackgroundRegion + { + /// + /// The rectangle where the background of the clip is drawn. + /// + /// + /// The rectangle is clipped to the screen. The rectangle does not include clip borders. + /// + public Rect position { get; private set; } + + /// + /// The start time of the region, relative to the clip. + /// + public double startTime { get; private set; } + + /// + /// The end time of the region, relative to the clip. + /// + public double endTime { get; private set; } + + /// + /// Constructor + /// + /// + /// + /// + public ClipBackgroundRegion(Rect _position, double _startTime, double _endTime) + { + position = _position; + startTime = _startTime; + endTime = _endTime; + } + + public override bool Equals(object obj) + { + if (!(obj is ClipBackgroundRegion)) + return false; + + return Equals((ClipBackgroundRegion)obj); + } + + public bool Equals(ClipBackgroundRegion other) + { + return position.Equals(other.position) && + startTime == other.startTime && + endTime == other.endTime; + } + + public override int GetHashCode() + { + return HashUtility.CombineHash( + position.GetHashCode(), + startTime.GetHashCode(), + endTime.GetHashCode() + ); + } + + public static bool operator==(ClipBackgroundRegion region1, ClipBackgroundRegion region2) + { + return region1.Equals(region2); + } + + public static bool operator!=(ClipBackgroundRegion region1, ClipBackgroundRegion region2) + { + return !region1.Equals(region2); + } + } + + /// + /// The user-defined options for drawing a clip. + /// + public struct ClipDrawOptions + { + private IEnumerable m_Icons; + + /// + /// Text that indicates if the clip should display an error. + /// + /// + /// If the error text is not empty or null, then the clip displays a warning. The error text is used as the tooltip. + /// + public string errorText { get; set; } + + /// + /// The tooltip to show for the clip. + /// + public string tooltip { get; set; } + + /// + /// The color drawn under the clip. By default, the color is the same as the track color. + /// + public Color highlightColor { get; set; } + + + /// + /// Icons to display on the clip. + /// + public IEnumerable icons + { + get { return m_Icons ?? System.Linq.Enumerable.Empty(); } + set { m_Icons = value;} + } + + public override bool Equals(object obj) + { + if (!(obj is ClipDrawOptions)) + return false; + + return Equals((ClipDrawOptions)obj); + } + + public bool Equals(ClipDrawOptions other) + { + return errorText == other.errorText && + tooltip == other.tooltip && + highlightColor == other.highlightColor && + System.Linq.Enumerable.SequenceEqual(icons, other.icons); + } + + public override int GetHashCode() + { + return HashUtility.CombineHash( + errorText != null ? errorText.GetHashCode() : 0, + tooltip != null ? tooltip.GetHashCode() : 0, + highlightColor.GetHashCode(), + icons != null ? icons.GetHashCode() : 0 + ); + } + + public static bool operator==(ClipDrawOptions options1, ClipDrawOptions options2) + { + return options1.Equals(options2); + } + + public static bool operator!=(ClipDrawOptions options1, ClipDrawOptions options2) + { + return !options1.Equals(options2); + } + } + + + /// + /// Use this class to customize clip types in the TimelineEditor. + /// + public class ClipEditor + { + static readonly string k_NoPlayableAssetError = LocalizationDatabase.GetLocalizedString("This clip does not contain a valid playable asset"); + static readonly string k_ScriptLoadError = LocalizationDatabase.GetLocalizedString("The associated script can not be loaded"); + + internal readonly bool supportsSubTimelines; + + /// + /// Default constructor + /// + public ClipEditor() + { + supportsSubTimelines = TypeUtility.HasOverrideMethod(GetType(), nameof(GetSubTimelines)); + } + + /// + /// Implement this method to override the default options for drawing a clip. + /// + /// The clip being drawn. + /// The options for drawing a clip. + public virtual ClipDrawOptions GetClipOptions(TimelineClip clip) + { + return new ClipDrawOptions() + { + errorText = GetErrorText(clip), + tooltip = string.Empty, + highlightColor = GetDefaultHighlightColor(clip), + icons = System.Linq.Enumerable.Empty() + }; + } + + /// + /// Override this method to draw a background for a clip . + /// + /// The clip being drawn. + /// The on-screen area where the clip is drawn. + public virtual void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) + { + } + + /// + /// Called when a clip is created. + /// + /// The newly created clip. + /// The track that the clip is assigned to. + /// The source that the clip was copied from. This can be set to null if the clip is not a copy. + /// + /// The callback occurs before the clip is assigned to the track. + /// + public virtual void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom) + { + } + + /// + /// Gets the error text for the specified clip. + /// + /// The clip being drawn. + /// Returns the error text to be displayed as the tool tip for the clip. If there is no error to be displayed, this method returns string.Empty. + public string GetErrorText(TimelineClip clip) + { + if (clip == null || clip.asset == null) + return k_NoPlayableAssetError; + + var playableAsset = clip.asset as ScriptableObject; + if (playableAsset == null || MonoScript.FromScriptableObject(playableAsset) == null) + return k_ScriptLoadError; + + return string.Empty; + } + + /// + /// The color drawn under the clip. By default, the color is the same as the track color. + /// + /// The clip being drawn. + /// Returns the highlight color of the clip being drawn. + public Color GetDefaultHighlightColor(TimelineClip clip) + { + if (clip == null) + return Color.white; + + return TrackResourceCache.GetTrackColor(clip.parentTrack); + } + + /// + /// Called when a clip is changed by the Editor. + /// + /// The clip that changed. + public virtual void OnClipChanged(TimelineClip clip) + { + } + + /// + /// Gets the sub-timelines for a specific clip. Implement this method if your clip supports playing nested timelines. + /// + /// The clip with the ControlPlayableAsset. + /// The playable director driving the Timeline Clip. This may not be the same as TimelineEditor.inspectedDirector. + /// Specify the sub-timelines to control. + public virtual void GetSubTimelines(TimelineClip clip, PlayableDirector director, List subTimelines) + { + } + } +} diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs.meta new file mode 100644 index 0000000..da1b7b5 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/ClipEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2537ddddebaa455409dec422eb08fd7e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs new file mode 100644 index 0000000..8211a98 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Playables; +using UnityEngine.Timeline; + +namespace UnityEditor.Timeline +{ + class CustomTimelineEditorCache + { + static class SubClassCache where TEditorClass : class, new() + { + private static Type[] s_SubClasses = null; + private static readonly TEditorClass s_DefaultInstance = new TEditorClass(); + private static readonly Dictionary s_TypeMap = new Dictionary(); + + public static TEditorClass DefaultInstance + { + get { return s_DefaultInstance; } + } + + static Type[] SubClasses + { + get + { + // order the subclass array by built-ins then user defined so built-in classes are chosen first + return s_SubClasses ?? + (s_SubClasses = TypeCache.GetTypesDerivedFrom().OrderBy(t => t.Assembly == typeof(UnityEditor.Timeline.TimelineEditor).Assembly ? 1 : 0).ToArray()); + } + } + + public static TEditorClass GetEditorForType(Type type) + { + TEditorClass editorClass = null; + if (!s_TypeMap.TryGetValue(type, out editorClass) || editorClass == null) + { + Type editorClassType = null; + Type searchType = type; + while (searchType != null) + { + // search our way up the runtime class hierarchy so we get the best match + editorClassType = GetExactEditorClassForType(searchType); + if (editorClassType != null) + break; + searchType = searchType.BaseType; + } + + if (editorClassType == null) + { + editorClass = s_DefaultInstance; + } + else + { + try + { + editorClass = (TEditorClass)Activator.CreateInstance(editorClassType); + } + catch (Exception e) + { + Debug.LogWarningFormat("Could not create a Timeline editor class of type {0}: {1}", editorClassType, e.Message); + editorClass = s_DefaultInstance; + } + } + + s_TypeMap[type] = editorClass; + } + + return editorClass; + } + + private static Type GetExactEditorClassForType(Type type) + { + foreach (var subClass in SubClasses) + { + // first check for exact match + var attr = (CustomTimelineEditorAttribute)Attribute.GetCustomAttribute(subClass, typeof(CustomTimelineEditorAttribute), false); + if (attr != null && attr.classToEdit == type) + { + return subClass; + } + } + + return null; + } + + public static void Clear() + { + s_TypeMap.Clear(); + s_SubClasses = null; + } + } + + public static TEditorClass GetEditorForType(Type type) where TEditorClass : class, new() + { + if (type == null) + throw new ArgumentNullException(nameof(type)); + + if (!typeof(TRuntimeClass).IsAssignableFrom(type)) + throw new ArgumentException(type.FullName + " does not inherit from" + typeof(TRuntimeClass)); + + return SubClassCache.GetEditorForType(type); + } + + public static void ClearCache() where TEditorClass : class, new() + { + SubClassCache.Clear(); + } + + public static ClipEditor GetClipEditor(TimelineClip clip) + { + if (clip == null) + throw new ArgumentNullException(nameof(clip)); + + var type = typeof(IPlayableAsset); + if (clip.asset != null) + type = clip.asset.GetType(); + + if (!typeof(IPlayableAsset).IsAssignableFrom(type)) + return GetDefaultClipEditor(); + + return GetEditorForType(type); + } + + public static ClipEditor GetDefaultClipEditor() + { + return SubClassCache.DefaultInstance; + } + + public static TrackEditor GetTrackEditor(TrackAsset track) + { + if (track == null) + throw new ArgumentNullException(nameof(track)); + + return GetEditorForType(track.GetType()); + } + + public static TrackEditor GetDefaultTrackEditor() + { + return SubClassCache.DefaultInstance; + } + + public static MarkerEditor GetMarkerEditor(IMarker marker) + { + if (marker == null) + throw new ArgumentNullException(nameof(marker)); + return GetEditorForType(marker.GetType()); + } + + public static MarkerEditor GetDefaultMarkerEditor() + { + return SubClassCache.DefaultInstance; + } + } +} diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs.meta new file mode 100644 index 0000000..03cae8e --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/CustomTimelineEditorCache.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fd6ede1d2f47ab146b2ec0a3969a37cc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs new file mode 100644 index 0000000..c0cf995 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs @@ -0,0 +1,209 @@ +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) + { + } + } +} diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs.meta new file mode 100644 index 0000000..7cbab44 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 99c5970046bb263469514e56eb6aa519 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs new file mode 100644 index 0000000..e6e06fb --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using UnityEngine.Timeline; + +namespace UnityEditor.Timeline +{ + [CustomTimelineEditor(typeof(MarkerTrack))] + class MarkerTrackEditor : TrackEditor + { + public static readonly float DefaultMarkerTrackHeight = 20; + + public override TrackDrawOptions GetTrackOptions(TrackAsset track, Object binding) + { + var options = base.GetTrackOptions(track, binding); + options.minimumHeight = DefaultMarkerTrackHeight; + return options; + } + } +} diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs.meta new file mode 100644 index 0000000..5c4b7a9 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/MarkerTrackEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 844873d1afe1c3142ab922324950e1dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs new file mode 100644 index 0000000..cd4f67c --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs @@ -0,0 +1,284 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Playables; +using UnityEngine.Timeline; + +namespace UnityEditor.Timeline +{ + /// + /// The user-defined options for drawing a track." + /// + public struct TrackDrawOptions + { + /// + /// Text that indicates if the track should display an error. + /// + /// + /// If the error text is not empty or null, then the track displays a warning. The error text is used as the tooltip. + /// + public string errorText { get; set; } + + /// + /// The highlight color of the track. + /// + public Color trackColor { get; set; } + + /// + /// The minimum height of the track. + /// + public float minimumHeight { get; set; } + + /// + /// The icon displayed on the track header. + /// + /// + /// If this value is null, then the default icon for the track is used. + /// + public Texture2D icon { get; set; } + + public override bool Equals(object obj) + { + if (!(obj is TrackDrawOptions)) + return false; + + return Equals((TrackDrawOptions)obj); + } + + public bool Equals(TrackDrawOptions other) + { + return errorText == other.errorText && + trackColor == other.trackColor && + minimumHeight == other.minimumHeight && + icon == other.icon; + } + + public override int GetHashCode() + { + return HashUtility.CombineHash( + errorText != null ? errorText.GetHashCode() : 0, + trackColor.GetHashCode(), + minimumHeight.GetHashCode(), + icon != null ? icon.GetHashCode() : 0 + ); + } + + public static bool operator==(TrackDrawOptions options1, TrackDrawOptions options2) + { + return options1.Equals(options2); + } + + public static bool operator!=(TrackDrawOptions options1, TrackDrawOptions options2) + { + return !options1.Equals(options2); + } + } + + + /// + /// The errors displayed for the track binding. + /// + public enum TrackBindingErrors + { + /// + /// Select no errors. + /// + None = 0, + + /// + /// The bound GameObject is disabled. + /// + BoundGameObjectDisabled = 1 << 0, + + /// + /// The bound GameObject does not have a valid component. + /// + NoValidComponent = 1 << 1, + + /// + /// The bound Object is a disabled Behaviour. + /// + BehaviourIsDisabled = 1 << 2, + + /// + /// The bound Object is not of the correct type. + /// + InvalidBinding = 1 << 3, + + /// + /// The bound Object is part of a prefab, and not an instance. + /// + PrefabBound = 1 << 4, + + /// + /// Select all errors. + /// + All = Int32.MaxValue + } + + /// + /// Use this class to customize track types in the TimelineEditor. + /// + public class TrackEditor + { + static readonly string k_BoundGameObjectDisabled = LocalizationDatabase.GetLocalizedString("The bound GameObject is disabled."); + static readonly string k_NoValidComponent = LocalizationDatabase.GetLocalizedString("Could not find appropriate component on this gameObject"); + static readonly string k_RequiredComponentIsDisabled = LocalizationDatabase.GetLocalizedString("The component is disabled"); + static readonly string k_InvalidBinding = LocalizationDatabase.GetLocalizedString("The bound object is not the correct type."); + static readonly string k_PrefabBound = LocalizationDatabase.GetLocalizedString("The bound object is a Prefab"); + + readonly Dictionary m_BindingCache = new Dictionary(); + + /// + /// The default height of a track. + /// + public static readonly float DefaultTrackHeight = 30.0f; + + /// + /// The minimum unscaled height of a track. + /// + public static readonly float MinimumTrackHeight = 10.0f; + + /// + /// The maximum height of a track. + /// + public static readonly float MaximumTrackHeight = 256.0f; + + /// + /// Implement this method to override the default options for drawing a track. + /// + /// The track from which track options are retrieved. + /// The binding for the track. + /// The options for drawing the track. + public virtual TrackDrawOptions GetTrackOptions(TrackAsset track, UnityEngine.Object binding) + { + return new TrackDrawOptions() + { + errorText = GetErrorText(track, binding, TrackBindingErrors.All), + minimumHeight = DefaultTrackHeight, + trackColor = GetTrackColor(track), + icon = null + }; + } + + /// + /// Gets the error text for the specified track. + /// + /// The track to retrieve options for. + /// The binding for the track. + /// The errors to check for. + /// An error to be displayed on the track, or string.Empty if there is no error. + public string GetErrorText(TrackAsset track, UnityEngine.Object boundObject, TrackBindingErrors detectErrors) + { + if (track == null || boundObject == null) + return string.Empty; + + var bindingType = GetBindingType(track); + if (bindingType != null) + { + // bound to a prefab asset + if (HasFlag(detectErrors, TrackBindingErrors.PrefabBound) && PrefabUtility.IsPartOfPrefabAsset(boundObject)) + { + return k_PrefabBound; + } + + // If we are a component, allow for bound game objects (legacy) + if (typeof(Component).IsAssignableFrom(bindingType)) + { + var gameObject = boundObject as GameObject; + var component = boundObject as Component; + if (component != null) + gameObject = component.gameObject; + + // game object is bound with no component + if (HasFlag(detectErrors, TrackBindingErrors.NoValidComponent) && gameObject != null && component == null) + { + component = gameObject.GetComponent(bindingType); + if (component == null) + { + return k_NoValidComponent; + } + } + + // attached gameObject is disables (ignores Activation Track) + if (HasFlag(detectErrors, TrackBindingErrors.BoundGameObjectDisabled) && gameObject != null && !gameObject.activeInHierarchy) + { + return k_BoundGameObjectDisabled; + } + + // component is disabled + var behaviour = component as Behaviour; + if (HasFlag(detectErrors, TrackBindingErrors.BehaviourIsDisabled) && behaviour != null && !behaviour.enabled) + { + return k_RequiredComponentIsDisabled; + } + + // mismatched binding + if (HasFlag(detectErrors, TrackBindingErrors.InvalidBinding) && component != null && !bindingType.IsAssignableFrom(component.GetType())) + { + return k_InvalidBinding; + } + } + // Mismatched binding (non-component) + else if (HasFlag(detectErrors, TrackBindingErrors.InvalidBinding) && !bindingType.IsAssignableFrom(boundObject.GetType())) + { + return k_InvalidBinding; + } + } + + return string.Empty; + } + + /// + /// Gets the color information of a track. + /// + /// + /// Returns the color for the specified track. + public Color GetTrackColor(TrackAsset track) + { + return TrackResourceCache.GetTrackColor(track); + } + + /// + /// Gets the binding type for a track. + /// + /// The track to retrieve the binding type from. + /// Returns the binding type for the specified track. Returns null if the track does not have binding. + public System.Type GetBindingType(TrackAsset track) + { + if (track == null) + return null; + + System.Type result = null; + if (m_BindingCache.TryGetValue(track, out result)) + return result; + + result = track.outputs.Select(x => x.outputTargetType).FirstOrDefault(); + m_BindingCache[track] = result; + return result; + } + + /// + /// Callback for when a track is created. + /// + /// The track that is created. + /// The source that the track is copied from. This can be set to null if the track is not a copy. + public virtual void OnCreate(TrackAsset track, TrackAsset copiedFrom) + { + } + + /// + /// Callback for when a track is changed. + /// + /// The track that is changed. + public virtual void OnTrackChanged(TrackAsset track) + { + } + + private static bool HasFlag(TrackBindingErrors errors, TrackBindingErrors flag) + { + return (errors & flag) != 0; + } + } +} diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs.meta new file mode 100644 index 0000000..a7ae571 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/CustomEditors/TrackEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35cb34351b19cf44ba78afbd58746610 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.2.3