From 4a2d76d30b3738c579a508781fd330803b5f38eb Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 30 Oct 2023 18:21:56 +0900 Subject: [PATCH] test: test animation length preserved --- Test~/ApplyObjectMappingTest.cs | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Test~/ApplyObjectMappingTest.cs b/Test~/ApplyObjectMappingTest.cs index 0ab5bf2c8..6f6ee44dd 100644 --- a/Test~/ApplyObjectMappingTest.cs +++ b/Test~/ApplyObjectMappingTest.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using UnityEditor; using UnityEditor.Animations; using UnityEngine; @@ -41,5 +42,41 @@ public void AvatarMask() Assert.That(avatarMask.GetHumanoidBodyPartActive(AvatarMaskBodyPart.Head), Is.True); Assert.That(avatarMask.GetHumanoidBodyPartActive(AvatarMaskBodyPart.LeftLeg), Is.False); } + + [Test] + public void PreserveAnimationLength() + { + var root = new GameObject(); + var child1 = Utils.NewGameObject("child1", root.transform); + var child11 = Utils.NewGameObject("child11", child1.transform); + var builder = new ObjectMappingBuilder(root); + + Object.DestroyImmediate(child11); + + var built = builder.BuildObjectMapping(); + + var rootMapper = new AnimatorControllerMapper(built.CreateAnimationMapper(root)); + + var animatorController = new AnimatorController(); + var layer = new AnimatorControllerLayer() + { + name = "layer", + stateMachine = new AnimatorStateMachine() { name = "layer" }, + }; + var state = layer.stateMachine.AddState("theState"); + var clip = new AnimationClip(); + clip.SetCurve("child1/child11", typeof(GameObject), "m_IsActive", AnimationCurve.Constant(0, 0.3f, 1)); + state.motion = clip; + animatorController.AddLayer(layer); + + var mappedController = rootMapper.MapAnimatorController(animatorController); + Assert.That(mappedController, Is.Not.EqualTo(animatorController)); + var mappedClip = mappedController.layers[0].stateMachine.states[0].state.motion as AnimationClip; + Assert.That(mappedClip, Is.Not.Null); + + Assert.That(mappedClip.length, Is.EqualTo(0.3f)); + Assert.That(AnimationUtility.GetCurveBindings(mappedClip)[0].path, + Contains.Substring("AvatarOptimizerClipLengthDummy")); + } } } \ No newline at end of file