diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
| commit | c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch) | |
| tree | ee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/TimeFieldDrawer.cs | |
| download | Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.gz Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.bz2 Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.zip | |
Inital commit
Diffstat (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/TimeFieldDrawer.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/TimeFieldDrawer.cs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/TimeFieldDrawer.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/TimeFieldDrawer.cs new file mode 100644 index 0000000..622f5b4 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/TimeFieldDrawer.cs @@ -0,0 +1,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); + } + } +} |
