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