TimelineTreeViewGUI.cs
5.73 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
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
class TimelineTreeViewGUI
{
readonly TimelineAsset m_Timeline;
readonly TreeViewController m_TreeView;
readonly TimelineTreeView m_TimelineTreeView;
readonly TimelineWindow m_Window;
readonly TimelineDataSource m_DataSource;
TreeViewItem root
{
get { return m_DataSource.root; }
}
TimelineTrackBaseGUI[] visibleTrackGuis
{
get
{
int firstRow;
int lastRow;
var visibleRows = new List<TimelineTrackBaseGUI>();
m_TreeView.gui.GetFirstAndLastRowVisible(out firstRow, out lastRow);
for (int r = firstRow; r <= lastRow; r++)
{
var track = m_TreeView.data.GetItem(r) as TimelineTrackBaseGUI;
if (track != null && track != root)
{
AddVisibleTrackRecursive(ref visibleRows, track);
}
}
return visibleRows.ToArray();
}
}
public TrackAsset[] visibleTracks
{
get { return visibleTrackGuis.Select(x => x.track).ToArray(); }
}
public List<TimelineClipGUI> allClipGuis
{
get
{
TimelineDataSource dataSource = m_TreeView.data as TimelineDataSource;
if (dataSource != null && dataSource.allTrackGuis != null)
return dataSource.allTrackGuis.OfType<TimelineTrackGUI>().SelectMany(x => x.clips).ToList();
return null;
}
}
public List<TimelineTrackBaseGUI> allTrackGuis
{
get
{
var dataSource = m_TreeView.data as TimelineDataSource;
if (dataSource != null)
return dataSource.allTrackGuis;
return null;
}
}
public Vector2 contentSize
{
get { return m_TreeView.GetContentSize(); }
}
public Vector2 scrollPosition
{
get { return m_TreeView.state.scrollPos; }
set
{
Rect r = m_TreeView.GetTotalRect();
Vector2 visibleContent = m_TreeView.GetContentSize();
m_TreeView.state.scrollPos = new Vector2(value.x, Mathf.Clamp(value.y, 0, Mathf.Max(0, visibleContent.y - r.height)));
}
}
public bool showingVerticalScrollBar
{
get { return m_TreeView.showingVerticalScrollBar; }
}
public void FrameItem(TreeViewItem item)
{
m_TreeView.Frame(item.id, true, false, true);
}
public TimelineDragging timelineDragging { get {return m_TreeView.dragging as TimelineDragging; }}
public TimelineTreeViewGUI(TimelineWindow sequencerWindow, TimelineAsset timeline, Rect rect)
{
m_Timeline = timeline;
m_Window = sequencerWindow;
var treeviewState = new TreeViewState();
treeviewState.scrollPos = new Vector2(treeviewState.scrollPos.x, TimelineWindowViewPrefs.GetOrCreateViewModel(m_Timeline).verticalScroll);
m_TreeView = new TreeViewController(sequencerWindow, treeviewState);
m_TreeView.horizontalScrollbarStyle = GUIStyle.none;
m_TreeView.scrollViewStyle = GUI.skin.scrollView;
m_TreeView.keyboardInputCallback = sequencerWindow.TreeViewKeyboardCallback;
m_TimelineTreeView = new TimelineTreeView(sequencerWindow, m_TreeView);
var dragging = new TimelineDragging(m_TreeView, m_Window, m_Timeline);
m_DataSource = new TimelineDataSource(this, m_TreeView, sequencerWindow);
m_DataSource.onVisibleRowsChanged += m_TimelineTreeView.CalculateRowRects;
m_TreeView.Init(rect, m_DataSource, m_TimelineTreeView, dragging);
m_DataSource.ExpandItems(m_DataSource.root);
}
public ITreeViewGUI gui
{
get { return m_TimelineTreeView; }
}
public ITreeViewDataSource data
{
get { return m_TreeView == null ? null : m_TreeView.data; }
}
public TimelineWindow TimelineWindow
{
get { return m_Window; }
}
public void CalculateRowRects()
{
m_TimelineTreeView.CalculateRowRects();
}
public void Reload()
{
AnimationClipCurveCache.Instance.ClearCachedProxyClips();
m_TreeView.ReloadData();
m_DataSource.ExpandItems(m_DataSource.root);
m_TimelineTreeView.CalculateRowRects();
}
public void OnGUI(Rect rect)
{
int keyboardControl = GUIUtility.GetControlID(FocusType.Passive, rect);
m_TreeView.OnGUI(rect, keyboardControl);
TimelineWindowViewPrefs.GetOrCreateViewModel(m_Timeline).verticalScroll = m_TreeView.state.scrollPos.y;
}
public Rect GetRowRect(int row)
{
return m_TimelineTreeView.GetRowRect(row);
}
static void AddVisibleTrackRecursive(ref List<TimelineTrackBaseGUI> list, TimelineTrackBaseGUI track)
{
if (track == null)
return;
list.Add(track);
if (!track.isExpanded)
return;
if (track.children != null)
{
foreach (var c in track.children)
{
AddVisibleTrackRecursive(ref list, c as TimelineTrackBaseGUI);
}
}
}
}
}