Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimelineTrackBaseGUI.cs 8.6KB

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