From 46577ed7f714e535f3cb820d9ef66ea42fff0dd7 Mon Sep 17 00:00:00 2001 From: {} Date: Wed, 10 Sep 2025 11:56:28 +0900 Subject: [PATCH] Added preserve toggle and selectable value state enum for mid-stop --- .../Editor/LitMotionAnimationEditor.cs | 1 + .../Runtime/LitMotionAnimation.cs | 7 +++++-- .../Runtime/PropertyAnimationComponent.cs | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs b/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs index e9bcd1cd..a39f7e1c 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs @@ -95,6 +95,7 @@ VisualElement CreateSettingsPanel() var box = CreateBox("Settings"); box.Add(new PropertyField(serializedObject.FindProperty("playOnAwake"))); box.Add(new PropertyField(serializedObject.FindProperty("animationMode"))); + box.Add(new PropertyField(serializedObject.FindProperty("preserve"))); return box; } diff --git a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs index 4351b75a..25658986 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs @@ -16,6 +16,7 @@ enum AnimationMode [SerializeField] bool playOnAwake = true; [SerializeField] AnimationMode animationMode; + [SerializeField] bool preserve = true; [SerializeReference] LitMotionAnimationComponent[] components; @@ -41,7 +42,8 @@ void MoveNextMotion() if (isActive) { - handle.Preserve(); + if (preserve) + handle.Preserve(); MotionManager.GetManagedDataRef(handle, false).OnCompleteAction += MoveNextMotion; } @@ -105,7 +107,8 @@ public void Play() if (handle.IsActive()) { - handle.Preserve(); + if (preserve) + handle.Preserve(); } playingComponents.Add(component); diff --git a/src/LitMotion/Assets/LitMotion.Animation/Runtime/PropertyAnimationComponent.cs b/src/LitMotion/Assets/LitMotion.Animation/Runtime/PropertyAnimationComponent.cs index 8ef4cb83..7c83cfa7 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Runtime/PropertyAnimationComponent.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Runtime/PropertyAnimationComponent.cs @@ -14,13 +14,25 @@ public abstract class PropertyAnimationComponent settings; [SerializeField] bool relative; + enum InterruptionValueState { StartValue, Stay, EndValue } + [SerializeField] InterruptionValueState interruptionValueState; - TValue startValue; + TValue startValue, endValue; public override void OnStop() { if (target == null) return; - SetValue(target, startValue); + switch (interruptionValueState) + { + case InterruptionValueState.StartValue: + SetValue(target, startValue); + break; + case InterruptionValueState.Stay: + break; + case InterruptionValueState.EndValue: + SetValue(target, endValue); + break; + } } public override MotionHandle Play() @@ -31,6 +43,7 @@ public override MotionHandle Play() if (relative) { + endValue = GetRelativeValue(startValue, settings.EndValue); handle = LMotion.Create(settings) .Bind(this, (x, state) => { @@ -39,6 +52,7 @@ public override MotionHandle Play() } else { + endValue = settings.EndValue; handle = LMotion.Create(settings) .Bind(this, (x, state) => {