From e4a61f6fd697c8de68cd0cea0371647be3530f9f Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 3 Nov 2023 09:36:23 +0900 Subject: [PATCH] test: preserve proxy animation --- Test~/ApplyObjectMappingTest.cs | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Test~/ApplyObjectMappingTest.cs b/Test~/ApplyObjectMappingTest.cs index 6f6ee44dd..e9830c23d 100644 --- a/Test~/ApplyObjectMappingTest.cs +++ b/Test~/ApplyObjectMappingTest.cs @@ -78,5 +78,49 @@ public void PreserveAnimationLength() Assert.That(AnimationUtility.GetCurveBindings(mappedClip)[0].path, Contains.Substring("AvatarOptimizerClipLengthDummy")); } + + [Test] + public void PreserveProxyAnimation() + { + 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; + + var proxyMotion = + AssetDatabase.LoadAssetAtPath( + AssetDatabase.GUIDToAssetPath("806c242c97b686d4bac4ad50defd1fdb")); + state = layer.stateMachine.AddState("afk"); + state.motion = proxyMotion; + + animatorController.AddLayer(layer); + + var mappedController = rootMapper.MapAnimatorController(animatorController); + Assert.That(mappedController, Is.Not.EqualTo(animatorController)); + + // ensure non-proxy mapped + var mappedClip = mappedController.layers[0].stateMachine.states[0].state.motion as AnimationClip; + Assert.That(mappedClip, Is.Not.EqualTo(clip)); + + mappedClip = mappedController.layers[0].stateMachine.states[1].state.motion as AnimationClip; + Assert.That(mappedClip, Is.EqualTo(proxyMotion)); + } } } \ No newline at end of file