A game about forced loneliness, made by TACStudios
1using UnityEngine;
2using UnityEngine.Playables;
3using UnityEngine.Timeline;
4
5namespace UnityEditor.Timeline
6{
7 partial class TimelineWindow
8 {
9 [SerializeField]
10 SequencePath m_SequencePath;
11
12 void OnSelectionChange()
13 {
14 //Sanitize the inline curve selection
15 SelectionManager.GetCurrentInlineEditorCurve()?.ValidateCurvesSelection();
16
17 RefreshSelection(false);
18 }
19
20 void RefreshSelection(bool forceRebuild)
21 {
22 // if we're in Locked mode, keep current selection - don't use locked property because the
23 // sequence hierarchy may need to be rebuilt and it assumes no asset == unlocked
24 if (m_LockTracker.isLocked || (state != null && state.recording))
25 {
26 RestoreLastSelection(forceRebuild);
27 return;
28 }
29
30 // selection is a TimelineAsset
31 Object selectedObject = Selection.activeObject as TimelineAsset;
32 if (selectedObject != null)
33 {
34 SetCurrentSelection(Selection.activeObject);
35 return;
36 }
37
38 // selection is a GameObject, or a prefab with a director
39 var selectedGO = Selection.activeGameObject;
40 if (selectedGO != null)
41 {
42 bool isSceneObject = !PrefabUtility.IsPartOfPrefabAsset(selectedGO);
43 bool hasDirector = selectedGO.GetComponent<PlayableDirector>() != null;
44 if (isSceneObject || hasDirector)
45 {
46 SetCurrentSelection(selectedGO);
47 return;
48 }
49 }
50
51 //If not currently editing a Timeline and the selection is empty, clear selection
52 if (Selection.activeObject == null &&
53 state.IsEditingAnEmptyTimeline())
54 {
55 SetCurrentSelection(null);
56 }
57
58
59 // otherwise, keep the same selection.
60 RestoreLastSelection(forceRebuild);
61 }
62
63 void RestoreLastSelection(bool forceRebuild)
64 {
65 state.SetCurrentSequencePath(m_SequencePath, forceRebuild);
66
67 //case 1201405 and 1278598: unlock the window if there is no valid asset, since the lock button is disabled
68 if (m_LockTracker.isLocked && state.editSequence.asset == null)
69 m_LockTracker.isLocked = false;
70 }
71
72 void SetCurrentSelection(Object obj)
73 {
74 var selectedGameObject = obj as GameObject;
75 if (selectedGameObject != null)
76 {
77 PlayableDirector director = TimelineUtility.GetDirectorComponentForGameObject(selectedGameObject);
78 SetTimeline(director);
79 }
80 else
81 {
82 var selectedSequenceAsset = obj as TimelineAsset;
83 if (selectedSequenceAsset != null)
84 {
85 SetTimeline(selectedSequenceAsset);
86 }
87 }
88
89 Repaint();
90 }
91 }
92}