TimelineDataSource.cs
7.77 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
class TimelineDataSource : TreeViewDataSource
{
readonly TimelineWindow m_TimelineWindow;
readonly TimelineTreeViewGUI m_ParentGUI;
public List<TimelineTrackBaseGUI> allTrackGuis { get; private set; }
TreeViewItem treeroot
{
get { return m_RootItem; }
}
public TimelineDataSource(TimelineTreeViewGUI parentGUI, TreeViewController treeView, TimelineWindow sequencerWindow)
: base(treeView)
{
m_TreeView.useExpansionAnimation = false;
m_TimelineWindow = sequencerWindow;
m_ParentGUI = parentGUI;
FetchData();
}
public override bool IsExpanded(TreeViewItem item)
{
if (!IsExpandable(item))
return true;
return IsExpanded(item.id);
}
public override bool IsExpandable(TreeViewItem item)
{
var expandable = false;
var track = item as TimelineTrackBaseGUI;
if (track != null)
expandable = track.expandable;
return expandable && item.hasChildren;
}
public sealed override void FetchData()
{
// create root item
m_RootItem = new TimelineGroupGUI(m_TreeView, m_ParentGUI, 1, 0, null, "root", null, true);
var tree = new Dictionary<TrackAsset, TimelineTrackBaseGUI>();
var filteredView = m_TimelineWindow.state.editSequence.asset.trackObjects;
allTrackGuis = new List<TimelineTrackBaseGUI>(filteredView.Count());
foreach (var t in filteredView)
{
CreateItem(t, ref tree, filteredView.OfType<TrackAsset>(), m_RootItem);
}
m_NeedRefreshRows = true;
SetExpanded(m_RootItem, true);
}
TimelineTrackBaseGUI CreateItem(ScriptableObject scriptableObject, ref Dictionary<TrackAsset, TimelineTrackBaseGUI> tree, IEnumerable<TrackAsset> selectedRows, TreeViewItem parentTreeViewItem)
{
// if a script doesn't load correctly, the trackAsset will be NULL, but the scriptableObject __should_ be intact (but == null will be true)
var trackAsset = scriptableObject as TrackAsset;
if (tree == null)
throw new ArgumentNullException("tree");
if (selectedRows == null)
throw new ArgumentNullException("selectedRows");
if (trackAsset != null && tree.ContainsKey(trackAsset))
return tree[trackAsset];
TimelineTrackBaseGUI parentItem = parentTreeViewItem as TimelineTrackBaseGUI;
// should we create the parent?
TrackAsset parentTrack = trackAsset != null ? (trackAsset.parent as TrackAsset) : null;
if (trackAsset != null && parentTrack != null && selectedRows.Contains(parentTrack))
{
parentItem = CreateItem(parentTrack, ref tree, selectedRows, parentTreeViewItem);
}
int theDepth = -1;
if (parentItem != null)
theDepth = parentItem.depth;
theDepth++;
TimelineTrackBaseGUI newItem;
if (trackAsset == null)
{
PlayableAsset parent = m_TimelineWindow.state.editSequence.asset;
if (parentItem != null && parentItem.track != null)
parent = parentItem.track;
newItem = new TimelineTrackErrorGUI(m_TreeView, m_ParentGUI, 0, theDepth, parentItem, "ERROR", scriptableObject, parent);
}
else if (trackAsset.GetType() != typeof(GroupTrack))
{
newItem = new TimelineTrackGUI(m_TreeView, m_ParentGUI, trackAsset.GetInstanceID(), theDepth, parentItem, trackAsset.name, trackAsset);
}
else
{
newItem = new TimelineGroupGUI(m_TreeView, m_ParentGUI, trackAsset.GetInstanceID(), theDepth, parentItem, trackAsset.name, trackAsset, false);
}
allTrackGuis.Add(newItem);
if (parentItem != null)
{
if (parentItem.children == null)
parentItem.children = new List<TreeViewItem>();
parentItem.children.Add(newItem);
}
else
{
m_RootItem = newItem;
SetExpanded(m_RootItem, true);
}
if (trackAsset != null)
tree[trackAsset] = newItem;
var actorAsAnimTrack = newItem.track as AnimationTrack;
bool isEditableInfiniteClip = actorAsAnimTrack != null && actorAsAnimTrack.ShouldShowInfiniteClipEditor();
if (isEditableInfiniteClip)
{
if (newItem.children == null)
newItem.children = new List<TreeViewItem>();
}
else if (trackAsset != null)
{
// check if clips on this track have animation, if so we inline a animationEditorTrack
bool clipHasAnimatableAnimationCurves = false;
for (var i = 0; i != newItem.track.clips.Length; ++i)
{
var curveClip = newItem.track.clips[i].curves;
var animationClip = newItem.track.clips[i].animationClip;
// prune out clip with zero curves
if (curveClip != null && curveClip.empty)
curveClip = null;
if (animationClip != null && animationClip.empty)
animationClip = null;
// prune out clips coming from FBX
if (animationClip != null && ((animationClip.hideFlags & HideFlags.NotEditable) != 0))
animationClip = null;
if (!newItem.track.clips[i].recordable)
animationClip = null;
clipHasAnimatableAnimationCurves = (curveClip != null) || (animationClip != null);
if (clipHasAnimatableAnimationCurves)
break;
}
if (clipHasAnimatableAnimationCurves)
{
if (newItem.children == null)
newItem.children = new List<TreeViewItem>();
}
}
if (trackAsset != null)
{
// Here we are using the internal subTrackObject so we can properly handle tracks whose script
// can't load (via ScriptableObject)
foreach (var subTrack in trackAsset.subTracksObjects)
{
CreateItem(subTrack, ref tree, selectedRows, newItem);
}
}
return newItem;
}
public override bool CanBeParent(TreeViewItem item)
{
// will prevent track becoming subtracks via dragging
TimelineTrackGUI track = item as TimelineTrackGUI;
if (track != null)
return false;
return true;
}
public void ExpandItems(TreeViewItem item)
{
if (treeroot == item)
{
SetExpanded(treeroot, true);
}
TimelineGroupGUI gui = item as TimelineGroupGUI;
if (gui != null && gui.track != null)
{
SetExpanded(item, !gui.track.GetCollapsed());
}
if (item.children != null)
{
for (int c = 0; c < item.children.Count; c++)
{
ExpandItems(item.children[c]);
}
}
}
}
}