Initial commit

This commit is contained in:
AbstractConcept 2022-09-13 00:36:34 -05:00
commit 3c7cc0c973
8391 changed files with 704313 additions and 0 deletions

View file

@ -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);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a371bcbba2084dd0a8ebc6826aa8794
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 926a61ff0dec44a5aab649acb411e9ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: