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