From 5689bc19c48e34853f1a7127ff692da97eeee9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Wed, 11 Oct 2023 11:37:06 +0200 Subject: [PATCH] Add ObjectReference keyframes --- .../V1/Editor/AacFlAnimations.cs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs index b38746e..81c9235 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs @@ -401,6 +401,50 @@ namespace AnimatorAsCode.V1 }); } } + + public void WithKeyframes(AacFlUnit unit, Action action) // FIXME: Should this be renamed? + { + var mutatedObjectReferenceKeyframes = new List(); + var builder = new AacFlSettingObjectReferenceKeyframes(unit, mutatedObjectReferenceKeyframes); + action.Invoke(builder); + + foreach (var binding in _bindings) + { + AnimationUtility.SetObjectReferenceCurve(_clip, binding, mutatedObjectReferenceKeyframes.ToArray()); + } + } + } + + public class AacFlSettingObjectReferenceKeyframes + { + private readonly AacFlUnit _unit; + private readonly List _mutatedKeyframes; + + public AacFlSettingObjectReferenceKeyframes(AacFlUnit unit, List mutatedKeyframes) + { + _unit = unit; + _mutatedKeyframes = mutatedKeyframes; + } + + public AacFlSettingObjectReferenceKeyframes Setting(int timeInUnit, Object value) + { + _mutatedKeyframes.Add(new ObjectReferenceKeyframe { time = AsSeconds(timeInUnit), value = value }); + + return this; + } + + private float AsSeconds(float timeInUnit) + { + switch (_unit) + { + case AacFlUnit.Frames: + return timeInUnit / 60f; + case AacFlUnit.Seconds: + return timeInUnit; + default: + throw new ArgumentOutOfRangeException(); + } + } } public class AacFlSettingCurveColor @@ -427,7 +471,7 @@ namespace AnimatorAsCode.V1 } } - public void WithKeyframes(AacFlUnit unit, Action action) + public void WithKeyframes(AacFlUnit unit, Action action) // FIXME: Should this be renamed? { var mutatedKeyframesR = new List(); var mutatedKeyframesG = new List();