TimeFieldDrawer.cs
2.36 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
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
[CustomPropertyDrawer(typeof(TimeFieldAttribute), true)]
class TimeFieldDrawer : PropertyDrawer
{
static WindowState state
{
get { return TimelineWindow.instance != null ? TimelineWindow.instance.state : null; }
}
static float currentFrameRate
{
get { return state != null ? TimelineWindow.instance.state.referenceSequence.frameRate : 0.0f; }
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.Float)
{
GUILayout.Label("TimeField only works on floating point types");
return;
}
var timeFieldAttribute = attribute as TimeFieldAttribute;
if (timeFieldAttribute == null)
return;
var rect = EditorGUILayout.s_LastRect;
EditorGUI.BeginChangeCheck();
if (timeFieldAttribute.useEditMode == TimeFieldAttribute.UseEditMode.ApplyEditMode)
TimeFieldWithEditMode(rect, property, label);
else
TimeField(rect, property, label);
if (EditorGUI.EndChangeCheck())
{
if (state != null)
state.Refresh();
}
}
static void TimeField(Rect rect, SerializedProperty property, GUIContent label)
{
var evt1 = InputEvent.None;
TimelineInspectorUtility.TimeField(rect, property, label, false, currentFrameRate, 0, float.MaxValue, ref evt1);
}
static void TimeFieldWithEditMode(Rect rect, SerializedProperty property, GUIContent label)
{
double minStartTime;
if (property.hasMultipleDifferentValues)
minStartTime = SelectionManager.SelectedItems().Min(i => i.start);
else
minStartTime = property.doubleValue;
var evt = InputEvent.None;
var newValue = TimelineInspectorUtility.TimeField(
rect, label, minStartTime, false, property.hasMultipleDifferentValues, currentFrameRate, 0.0, float.MaxValue, ref evt);
EditMode.inputHandler.ProcessMove(evt, newValue);
}
}
}