Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TimelineWindow_TrackGui.cs 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.Playables;
  6. namespace UnityEditor.Timeline
  7. {
  8. partial class TimelineWindow
  9. {
  10. public TimelineTreeViewGUI treeView { get; private set; }
  11. void TracksGUI(Rect clientRect, WindowState state, TimelineModeGUIState trackState)
  12. {
  13. if (Event.current.type == EventType.Repaint && treeView != null)
  14. {
  15. state.headerSpacePartitioner.Clear();
  16. state.spacePartitioner.Clear();
  17. }
  18. if (state.IsEditingASubTimeline() && !state.IsEditingAnEmptyTimeline())
  19. {
  20. var headerRect = clientRect;
  21. headerRect.width = state.sequencerHeaderWidth;
  22. Graphics.DrawBackgroundRect(state, headerRect);
  23. var clipRect = clientRect;
  24. clipRect.xMin = headerRect.xMax;
  25. Graphics.DrawBackgroundRect(state, clipRect, subSequenceMode: true);
  26. }
  27. else
  28. {
  29. Graphics.DrawBackgroundRect(state, clientRect);
  30. }
  31. if (!state.IsEditingAnEmptyTimeline())
  32. m_TimeArea.DrawMajorTicks(sequenceContentRect, (float)state.referenceSequence.frameRate);
  33. GUILayout.BeginVertical();
  34. {
  35. GUILayout.Space(5.0f);
  36. GUILayout.BeginHorizontal();
  37. if (this.state.editSequence.asset == null)
  38. DrawNoSequenceGUI(state);
  39. else
  40. DrawTracksGUI(clientRect, trackState);
  41. GUILayout.EndHorizontal();
  42. }
  43. GUILayout.EndVertical();
  44. Graphics.DrawShadow(clientRect);
  45. }
  46. void DrawNoSequenceGUI(WindowState windowState)
  47. {
  48. bool showCreateButton = false;
  49. var currentlySelectedGo = UnityEditor.Selection.activeObject != null ? UnityEditor.Selection.activeObject as GameObject : null;
  50. var textContent = DirectorStyles.noTimelineAssetSelected;
  51. var existingDirector = currentlySelectedGo != null ? currentlySelectedGo.GetComponent<PlayableDirector>() : null;
  52. var existingAsset = existingDirector != null ? existingDirector.playableAsset : null;
  53. if (currentlySelectedGo != null && !TimelineUtility.IsPrefabOrAsset(currentlySelectedGo) && existingAsset == null)
  54. {
  55. showCreateButton = true;
  56. textContent = new GUIContent(String.Format(DirectorStyles.createTimelineOnSelection.text, currentlySelectedGo.name, L10n.Tr("a Director component and a Timeline asset")));
  57. }
  58. GUILayout.FlexibleSpace();
  59. GUILayout.BeginVertical();
  60. GUILayout.FlexibleSpace();
  61. GUILayout.Label(textContent);
  62. if (showCreateButton)
  63. {
  64. GUILayout.BeginHorizontal();
  65. var textSize = GUI.skin.label.CalcSize(textContent);
  66. GUILayout.Space((textSize.x / 2.0f) - (WindowConstants.createButtonWidth / 2.0f));
  67. if (GUILayout.Button(L10n.Tr("Create"), GUILayout.Width(WindowConstants.createButtonWidth)))
  68. {
  69. var message = DirectorStyles.createNewTimelineText.text + " '" + currentlySelectedGo.name + "'";
  70. var defaultName = currentlySelectedGo.name.EndsWith(DirectorStyles.newTimelineDefaultNameSuffix, StringComparison.OrdinalIgnoreCase)
  71. ? currentlySelectedGo.name
  72. : currentlySelectedGo.name + DirectorStyles.newTimelineDefaultNameSuffix;
  73. // Use the project window path by default only if it's under the asset folder.
  74. // Otherwise the saveFilePanel will reject the save (case 1289923)
  75. var defaultPath = ProjectWindowUtil.GetActiveFolderPath();
  76. if (!defaultPath.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase))
  77. defaultPath = "Assets";
  78. string newSequencePath = EditorUtility.SaveFilePanelInProject(DirectorStyles.createNewTimelineText.text, defaultName, "playable", message, defaultPath);
  79. if (!string.IsNullOrEmpty(newSequencePath))
  80. {
  81. var newAsset = TimelineUtility.CreateAndSaveTimelineAsset(newSequencePath);
  82. Undo.IncrementCurrentGroup();
  83. if (existingDirector == null)
  84. {
  85. existingDirector = Undo.AddComponent<PlayableDirector>(currentlySelectedGo);
  86. }
  87. existingDirector.playableAsset = newAsset;
  88. SetTimeline(existingDirector);
  89. windowState.previewMode = false;
  90. }
  91. // If we reach this point, the state of the panel has changed; skip the rest of this GUI phase
  92. // Fixes: case 955831 - [OSX] NullReferenceException when creating a timeline on a selected object
  93. GUIUtility.ExitGUI();
  94. }
  95. GUILayout.EndHorizontal();
  96. }
  97. GUILayout.FlexibleSpace();
  98. GUILayout.EndVertical();
  99. GUILayout.FlexibleSpace();
  100. }
  101. internal List<OverlayDrawer> OverlayDrawData = new List<OverlayDrawer>();
  102. void DrawTracksGUI(Rect clientRect, TimelineModeGUIState trackState)
  103. {
  104. GUILayout.BeginVertical(GUILayout.Height(clientRect.height));
  105. if (treeView != null)
  106. {
  107. if (Event.current.type == EventType.Layout)
  108. {
  109. OverlayDrawData.Clear();
  110. }
  111. treeView.OnGUI(clientRect);
  112. if (Event.current.type == EventType.Repaint)
  113. {
  114. foreach (var overlayData in OverlayDrawData)
  115. {
  116. using (new GUIViewportScope(sequenceContentRect))
  117. overlayData.Draw();
  118. }
  119. }
  120. }
  121. GUILayout.EndVertical();
  122. }
  123. }
  124. }