summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner
diff options
context:
space:
mode:
Diffstat (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner')
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs109
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs.meta11
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs14
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs.meta11
4 files changed, 145 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs
new file mode 100644
index 0000000..c5c4405
--- /dev/null
+++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs
@@ -0,0 +1,109 @@
+using System;
+using UnityEngine;
+using UnityEngine.Timeline;
+
+namespace UnityEditor.Timeline
+{
+ static class CurvesOwnerInspectorHelper
+ {
+ // Because what is animated is not the asset, but the instanced playable,
+ // we apply the animation clip here to preview what is being shown
+ // This could be improved doing something more inline with animation mode,
+ // and reverting values that aren't be recorded later to avoid dirtying the asset
+ public static void PreparePlayableAsset(ICurvesOwnerInspectorWrapper wrapper)
+ {
+ if (Event.current.type != EventType.Repaint)
+ return;
+
+ if (wrapper.serializedPlayableAsset == null)
+ return;
+
+ var curvesOwner = wrapper.curvesOwner;
+ if (curvesOwner == null || curvesOwner.curves == null)
+ return;
+
+ var timelineWindow = TimelineWindow.instance;
+ if (timelineWindow == null || timelineWindow.state == null)
+ return;
+
+ // requires preview mode. reset the eval time so previous value is correct value is displayed while toggling
+ if (!timelineWindow.state.previewMode)
+ {
+ wrapper.lastEvalTime = -1;
+ return;
+ }
+
+ var time = wrapper.ToLocalTime(timelineWindow.state.editSequence.time);
+
+ // detect if the time has changed, or if the curves have changed
+ if (Math.Abs(wrapper.lastEvalTime - time) < TimeUtility.kTimeEpsilon)
+ {
+ int curveVersion = AnimationClipCurveCache.Instance.GetCurveInfo(curvesOwner.curves).version;
+ if (curveVersion == wrapper.lastCurveVersion)
+ return;
+
+ wrapper.lastCurveVersion = curveVersion;
+ }
+
+ wrapper.lastEvalTime = time;
+
+ var clipInfo = AnimationClipCurveCache.Instance.GetCurveInfo(curvesOwner.curves);
+ int count = clipInfo.bindings.Length;
+ if (count == 0)
+ return;
+
+ wrapper.serializedPlayableAsset.Update();
+
+ var prop = wrapper.serializedPlayableAsset.GetIterator();
+ while (prop.NextVisible(true))
+ {
+ if (curvesOwner.IsParameterAnimated(prop.propertyPath))
+ {
+ var curve = curvesOwner.GetAnimatedParameter(prop.propertyPath);
+ switch (prop.propertyType)
+ {
+ case SerializedPropertyType.Boolean:
+ prop.boolValue = curve.Evaluate((float)time) > 0;
+ break;
+ case SerializedPropertyType.Float:
+ prop.floatValue = curve.Evaluate((float)time);
+ break;
+ case SerializedPropertyType.Integer:
+ prop.intValue = Mathf.FloorToInt(curve.Evaluate((float)time));
+ break;
+ case SerializedPropertyType.Color:
+ SetAnimatedValue(curvesOwner, prop, "r", time);
+ SetAnimatedValue(curvesOwner, prop, "g", time);
+ SetAnimatedValue(curvesOwner, prop, "b", time);
+ SetAnimatedValue(curvesOwner, prop, "a", time);
+ break;
+ case SerializedPropertyType.Quaternion:
+ case SerializedPropertyType.Vector4:
+ SetAnimatedValue(curvesOwner, prop, "w", time);
+ goto case SerializedPropertyType.Vector3;
+ case SerializedPropertyType.Vector3:
+ SetAnimatedValue(curvesOwner, prop, "z", time);
+ goto case SerializedPropertyType.Vector2;
+ case SerializedPropertyType.Vector2:
+ SetAnimatedValue(curvesOwner, prop, "x", time);
+ SetAnimatedValue(curvesOwner, prop, "y", time);
+ break;
+ }
+ }
+ }
+
+ wrapper.serializedPlayableAsset.ApplyModifiedPropertiesWithoutUndo();
+ }
+
+ static void SetAnimatedValue(ICurvesOwner clip, SerializedProperty property, string path, double localTime)
+ {
+ var prop = property.FindPropertyRelative(path);
+ if (prop != null)
+ {
+ var curve = clip.GetAnimatedParameter(prop.propertyPath);
+ if (curve != null)
+ prop.floatValue = curve.Evaluate((float)localTime);
+ }
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs.meta
new file mode 100644
index 0000000..17e8bb3
--- /dev/null
+++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/CurvesOwnerInspectorHelper.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9a371bcbba2084dd0a8ebc6826aa8794
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs
new file mode 100644
index 0000000..0ce6f58
--- /dev/null
+++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs
@@ -0,0 +1,14 @@
+using UnityEngine.Timeline;
+
+namespace UnityEditor.Timeline
+{
+ interface ICurvesOwnerInspectorWrapper
+ {
+ ICurvesOwner curvesOwner { get; }
+ SerializedObject serializedPlayableAsset { get; }
+ int lastCurveVersion { get; set; }
+ double lastEvalTime { get; set; }
+
+ double ToLocalTime(double time);
+ }
+}
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs.meta b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs.meta
new file mode 100644
index 0000000..746e970
--- /dev/null
+++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/inspectors/CurvesOwner/ICurvesOwnerInspectorWrapper.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 926a61ff0dec44a5aab649acb411e9ad
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: