TrackAssetInspector.cs
6.43 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
//#define PERF_PROFILE
using System.Linq;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
[CustomEditor(typeof(TrackAsset), true, isFallback = true)]
[CanEditMultipleObjects]
class TrackAssetInspector : Editor
{
class TrackCurvesWrapper : ICurvesOwnerInspectorWrapper
{
public ICurvesOwner curvesOwner { get; }
public SerializedObject serializedPlayableAsset { get; }
public int lastCurveVersion { get; set; }
public double lastEvalTime { get; set; }
public TrackCurvesWrapper(TrackAsset track)
{
lastCurveVersion = -1;
lastEvalTime = -1;
if (track != null)
{
curvesOwner = track;
serializedPlayableAsset = new SerializedObject(track);
}
}
public double ToLocalTime(double time)
{
return time;
}
}
TrackCurvesWrapper m_TrackCurvesWrapper;
SerializedProperty m_Name;
bool m_IsBuiltInType;
Texture m_HeaderIcon;
protected TimelineWindow timelineWindow
{
get
{
return TimelineWindow.instance;
}
}
protected bool IsTrackLocked()
{
if (!TimelineUtility.IsCurrentSequenceValid() || IsCurrentSequenceReadOnly())
return true;
return targets.Any(track => ((TrackAsset)track).lockedInHierarchy);
}
public override void OnInspectorGUI()
{
using (new EditorGUI.DisabledScope(IsTrackLocked()))
{
DrawInspector();
}
}
internal override bool IsEnabled()
{
return TimelineUtility.IsCurrentSequenceValid() && !IsCurrentSequenceReadOnly() && base.IsEnabled();
}
internal override void OnHeaderTitleGUI(Rect titleRect, string header)
{
serializedObject.Update();
var textFieldRect = titleRect;
using (new GUIMixedValueScope(m_Name.hasMultipleDifferentValues))
{
var seqWindow = TimelineWindow.instance;
if (IsTrackLocked())
{
base.OnHeaderTitleGUI(titleRect, m_Name.stringValue);
}
else
{
EditorGUI.BeginChangeCheck();
string newName = EditorGUI.DelayedTextField(textFieldRect, m_Name.stringValue, EditorStyles.textField);
if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(newName))
{
for (int c = 0; c < targets.Length; c++)
{
ObjectNames.SetNameSmart(targets[c], newName);
}
if (seqWindow != null)
seqWindow.Repaint();
}
serializedObject.ApplyModifiedProperties();
}
}
}
internal override void OnHeaderIconGUI(Rect iconRect)
{
if (TimelineWindow.instance == null)
return;
using (new EditorGUI.DisabledScope(IsTrackLocked()))
{
if (m_HeaderIcon != null)
GUI.Label(iconRect, GUIContent.Temp(m_HeaderIcon));
}
}
internal override Rect DrawHeaderHelpAndSettingsGUI(Rect r)
{
using (new EditorGUI.DisabledScope(IsTrackLocked()))
{
var helpSize = EditorStyles.iconButton.CalcSize(EditorGUI.GUIContents.helpIcon);
const int kTopMargin = 5;
// Show Editor Header Items.
return EditorGUIUtility.DrawEditorHeaderItems(new Rect(r.xMax - helpSize.x, r.y + kTopMargin, helpSize.x, helpSize.y), targets);
}
}
public virtual void OnEnable()
{
m_IsBuiltInType = target != null && target.GetType().Assembly == typeof(TrackAsset).Assembly;
m_Name = serializedObject.FindProperty("m_Name");
m_TrackCurvesWrapper = new TrackCurvesWrapper(target as TrackAsset);
m_HeaderIcon = TrackResourceCache.s_DefaultIcon.image;
// only worry about the first track. if types are different, a different inspector is used.
var track = target as TrackAsset;
if (track != null)
{
var drawer = CustomTimelineEditorCache.GetTrackEditor(track);
UnityEngine.Object binding = null;
var director = m_Context as PlayableDirector;
if (director != null)
binding = director.GetGenericBinding(track);
var options = drawer.GetTrackOptions(track, binding);
if (options.icon != null)
m_HeaderIcon = options.icon;
else
m_HeaderIcon = TrackResourceCache.GetTrackIcon(track).image;
}
}
void DrawInspector()
{
if (serializedObject == null)
return;
CurvesOwnerInspectorHelper.PreparePlayableAsset(m_TrackCurvesWrapper);
serializedObject.Update();
using (var changeScope = new EditorGUI.ChangeCheckScope())
{
DrawTrackProperties();
if (changeScope.changed)
{
serializedObject.ApplyModifiedProperties();
ApplyChanges();
}
}
}
protected virtual void DrawTrackProperties()
{
var property = serializedObject.GetIterator();
var expanded = true;
while (property.NextVisible(expanded))
{
// Don't draw script field for built-in types
if (m_IsBuiltInType && "m_Script" == property.propertyPath)
continue;
EditorGUILayout.PropertyField(property, !expanded);
expanded = false;
}
}
protected virtual void ApplyChanges()
{
TimelineEditor.Refresh(RefreshReason.ContentsModified);
}
static bool IsCurrentSequenceReadOnly()
{
return TimelineWindow.instance.state.editSequence.isReadOnly;
}
}
}