A game about forced loneliness, made by TACStudios
at master 214 lines 8.8 kB view raw
1using UnityEditor.IMGUI.Controls; 2using UnityEngine; 3using UnityEngine.Timeline; 4 5namespace UnityEditor.Timeline 6{ 7 abstract class TimelineTrackBaseGUI : TreeViewItem, IBounds 8 { 9 static class Styles 10 { 11 public static readonly GUIContent s_LockedAndMuted = L10n.TextContent("Locked / Muted"); 12 public static readonly GUIContent s_LockedAndPartiallyMuted = L10n.TextContent("Locked / Partially Muted"); 13 public static readonly GUIContent s_Locked = L10n.TextContent("Locked"); 14 public static readonly GUIContent s_Muted = L10n.TextContent("Muted"); 15 public static readonly GUIContent s_PartiallyMuted = L10n.TextContent("Partially Muted"); 16 17 public static readonly GUIContent trackMuteBtnOnTooltip = L10n.TextContent(string.Empty, "Umute"); 18 public static readonly GUIContent trackMuteBtnOffTooltip = L10n.TextContent(string.Empty, "Mute"); 19 public static readonly GUIContent trackLockBtnOnTooltip = L10n.TextContent(string.Empty, "Unlock"); 20 public static readonly GUIContent trackLockBtnOffTooltip = L10n.TextContent(string.Empty, "Lock"); 21 22 public static readonly Texture2D lockBg = DirectorStyles.GetBackgroundImage(DirectorStyles.Instance.trackLockOverlay); 23 } 24 25 protected bool m_IsRoot = false; 26 27 readonly TimelineTreeViewGUI m_TreeViewGUI; 28 readonly TrackDrawer m_Drawer; 29 30 public Vector2 treeViewToWindowTransformation { get; set; } 31 public bool isExpanded { get; set; } 32 public bool isDropTarget { protected get; set; } 33 public TrackAsset track { get; } 34 TreeViewController treeView { get; } 35 36 public TimelineWindow TimelineWindow 37 { 38 get 39 { 40 if (m_TreeViewGUI == null) 41 return null; 42 43 return m_TreeViewGUI.TimelineWindow; 44 } 45 } 46 47 public TrackDrawer drawer 48 { 49 get { return m_Drawer; } 50 } 51 52 public virtual float GetVerticalSpacingBetweenTracks() 53 { 54 return 3.0f; 55 } 56 57 public bool visibleRow { get; set; } // is the header row visible 58 public bool visibleExpanded { get; set; } // is the expanded area (group) visible 59 public bool drawInsertionMarkerBefore { get; set; } 60 public bool drawInsertionMarkerAfter { get; set; } 61 62 public abstract Rect boundingRect { get; } 63 public abstract bool expandable { get; } 64 public abstract void Draw(Rect headerRect, Rect contentRect, WindowState state); 65 public abstract void OnGraphRebuilt(); // callback when the corresponding graph is rebuilt. This can happen, but not have the GUI rebuilt. 66 67 protected TimelineTrackBaseGUI(int id, int depth, TreeViewItem parent, string displayName, TrackAsset trackAsset, TreeViewController tv, TimelineTreeViewGUI tvgui) 68 : base(id, depth, parent, displayName) 69 { 70 m_Drawer = TrackDrawer.CreateInstance(trackAsset); 71 m_Drawer.sequencerState = tvgui.TimelineWindow.state; 72 73 isExpanded = false; 74 isDropTarget = false; 75 track = trackAsset; 76 treeView = tv; 77 78 m_TreeViewGUI = tvgui; 79 } 80 81 public static TimelineTrackBaseGUI FindGUITrack(TrackAsset track) 82 { 83 var allTracks = TimelineWindow.instance.allTracks; 84 return allTracks.Find(x => x.track == track); 85 } 86 87 protected void DrawTrackState(Rect trackRect, Rect expandedRect, TrackAsset track) 88 { 89 if (Event.current.type == EventType.Layout) 90 { 91 bool needStateBox = false; 92 93 //Mute 94 if (track.muted && !TimelineUtility.IsParentMuted(track)) 95 { 96 Rect bgRect = expandedRect; 97 TimelineWindow.instance.OverlayDrawData.Add(OverlayDrawer.CreateColorOverlay( 98 GUIClip.Unclip(bgRect), 99 DirectorStyles.Instance.customSkin.colorTrackDarken)); 100 needStateBox = true; 101 } 102 103 //Lock 104 if (!needStateBox && track.locked && !TimelineUtility.IsLockedFromGroup(track)) 105 { 106 Rect bgRect = expandedRect; 107 TimelineWindow.instance.OverlayDrawData.Add(OverlayDrawer.CreateTextureOverlay( 108 GUIClip.Unclip(bgRect), 109 Styles.lockBg)); 110 needStateBox = true; 111 } 112 113 if (needStateBox) 114 { 115 DrawTrackStateBox(trackRect, track); 116 } 117 } 118 } 119 120 static void DrawTrackStateBox(Rect trackRect, TrackAsset track) 121 { 122 var styles = DirectorStyles.Instance; 123 124 bool locked = track.locked && !TimelineUtility.IsLockedFromGroup(track); 125 bool muted = track.muted && !TimelineUtility.IsParentMuted(track); 126 bool allSubTrackMuted = TimelineUtility.IsAllSubTrackMuted(track); 127 128 GUIContent content = null; 129 if (locked && muted) 130 { 131 content = Styles.s_LockedAndMuted; 132 if (!allSubTrackMuted) 133 content = Styles.s_LockedAndPartiallyMuted; 134 } 135 else if (locked) content = Styles.s_Locked; 136 else if (muted) 137 { 138 content = Styles.s_Muted; 139 if (!allSubTrackMuted) 140 content = Styles.s_PartiallyMuted; 141 } 142 143 // the track could be locked, but we only show the 'locked portion' on the upper most track 144 // that is causing the lock 145 if (content == null) 146 return; 147 148 Rect textRect = Graphics.CalculateTextBoxSize(trackRect, styles.fontClip, content, WindowConstants.overlayTextPadding); 149 150 TimelineWindow.instance.OverlayDrawData.Add( 151 OverlayDrawer.CreateTextBoxOverlay( 152 GUIClip.Unclip(textRect), 153 content.text, styles.fontClip, 154 Color.white, 155 styles.customSkin.colorLockTextBG, 156 styles.displayBackground)); 157 } 158 159 protected void DrawMuteButton(Rect rect, WindowState state) 160 { 161 using (new EditorGUI.DisabledScope(TimelineUtility.IsParentMuted(track))) 162 { 163 EditorGUI.BeginChangeCheck(); 164 var isMuted = track.mutedInHierarchy; 165 var tooltip = isMuted ? Styles.trackMuteBtnOnTooltip : Styles.trackMuteBtnOffTooltip; 166 var muted = GUI.Toggle(rect, isMuted, tooltip, TimelineWindow.styles.trackMuteButton); 167 if (EditorGUI.EndChangeCheck()) 168 MuteTrack.Mute(new[] { track }, muted); 169 } 170 } 171 172 protected void DrawLockButton(Rect rect, WindowState state) 173 { 174 using (new EditorGUI.DisabledScope(TimelineUtility.IsLockedFromGroup(track))) 175 { 176 EditorGUI.BeginChangeCheck(); 177 var isLocked = track.lockedInHierarchy; 178 var tooltip = isLocked ? Styles.trackLockBtnOnTooltip : Styles.trackLockBtnOffTooltip; 179 var locked = GUI.Toggle(rect, track.lockedInHierarchy, tooltip, TimelineWindow.styles.trackLockButton); 180 if (EditorGUI.EndChangeCheck()) 181 LockTrack.SetLockState(new[] { track }, locked); 182 } 183 } 184 185 public void DrawInsertionMarkers(Rect rowRectWithIndent) 186 { 187 const float insertionHeight = WindowConstants.trackInsertionMarkerHeight; 188 if (Event.current.type == EventType.Repaint && (drawInsertionMarkerAfter || drawInsertionMarkerBefore)) 189 { 190 if (drawInsertionMarkerBefore) 191 { 192 var rect = new Rect(rowRectWithIndent.x, rowRectWithIndent.y - insertionHeight * 0.5f - 2.0f, rowRectWithIndent.width, insertionHeight); 193 EditorGUI.DrawRect(rect, Color.white); 194 } 195 196 if (drawInsertionMarkerAfter) 197 { 198 var rect = new Rect(rowRectWithIndent.x, rowRectWithIndent.y + rowRectWithIndent.height - insertionHeight * 0.5f + 1.0f, rowRectWithIndent.width, insertionHeight); 199 EditorGUI.DrawRect(rect, Color.white); 200 } 201 } 202 } 203 204 public void ClearDrawFlags() 205 { 206 if (Event.current.type == EventType.Repaint) 207 { 208 isDropTarget = false; 209 drawInsertionMarkerAfter = false; 210 drawInsertionMarkerBefore = false; 211 } 212 } 213 } 214}