From c3e0f944485f162e29894d1a3e1459fca499d676 Mon Sep 17 00:00:00 2001 From: bd_ Date: Fri, 6 Jan 2023 23:54:48 +0900 Subject: [PATCH] chore: Add TransformMappingThroughSwitchedObject test --- .../AnimateAddedBones/AnimateAddedBones.cs | 16 ++-------- .../_ModularAvatar/EditModeTests/TestBase.cs | 29 +++++++++++++++++++ ...TransformMappingThroughSwitchedObject.meta | 0 .../TMTSO_BaseFX.controller | 0 .../TMTSO_BaseFX.controller.meta | 0 .../TMTSO_ChildController.controller | 4 +-- .../TMTSO_ChildController.controller.meta | 0 .../TMTSO_Empty.anim | 0 .../TMTSO_Empty.anim.meta | 0 .../TMTSO_Rotate.anim | 0 .../TMTSO_Rotate.anim.meta | 0 .../TMTSO_Toggle.anim | 0 .../TMTSO_Toggle.anim.meta | 0 .../TransformMappingThroughSwitchedObject.cs | 27 +++++++++++++++++ ...nsformMappingThroughSwitchedObject.cs.meta | 3 ++ ...ansformMappingThroughSwitchedObject.prefab | 0 ...rmMappingThroughSwitchedObject.prefab.meta | 0 17 files changed, 63 insertions(+), 16 deletions(-) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller (97%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim.meta (100%) create mode 100644 Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs create mode 100644 Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs.meta rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab.meta (100%) diff --git a/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs index 1ef7f7af..10844096 100644 --- a/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs +++ b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs @@ -20,21 +20,9 @@ namespace modular_avatar_tests.AnimateAddedBones var prefab = CreatePrefab("AnimateAddedBones.prefab"); AvatarProcessor.ProcessAvatar(prefab); - var fx = prefab.GetComponent().baseAnimationLayers - .FirstOrDefault(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX); + var layerName = "merged"; - Assert.NotNull(fx); - var ac = fx.animatorController as AnimatorController; - Assert.NotNull(ac); - Assert.False(fx.isDefault); - - var layer = ac.layers.FirstOrDefault(l => l.name == "merged"); - Assert.NotNull(layer); - var state = layer.stateMachine.states[0].state; - Assert.NotNull(state); - - var motion = state.motion as AnimationClip; - Assert.NotNull(motion); + var motion = findFxMotion(prefab, layerName); var cubeObject = prefab.transform.Find("Armature/Hips").GetChild(0).gameObject; Assert.True(cubeObject.name.StartsWith("Cube$")); diff --git a/Assets/_ModularAvatar/EditModeTests/TestBase.cs b/Assets/_ModularAvatar/EditModeTests/TestBase.cs index bdcaa472..4d99ff93 100644 --- a/Assets/_ModularAvatar/EditModeTests/TestBase.cs +++ b/Assets/_ModularAvatar/EditModeTests/TestBase.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.Linq; using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; using UnityEditor; +using UnityEditor.Animations; using UnityEngine; using VRC.SDK3.Avatars.Components; @@ -61,5 +63,32 @@ namespace modular_avatar_tests objects.Add(go); return go; } + + + protected static AnimationClip findFxMotion(GameObject prefab, string layerName) + { + var layer = findFxLayer(prefab, layerName); + var state = layer.stateMachine.states[0].state; + Assert.NotNull(state); + + var motion = state.motion as AnimationClip; + Assert.NotNull(motion); + return motion; + } + + protected static AnimatorControllerLayer findFxLayer(GameObject prefab, string layerName) + { + var fx = prefab.GetComponent().baseAnimationLayers + .FirstOrDefault(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX); + + Assert.NotNull(fx); + var ac = fx.animatorController as AnimatorController; + Assert.NotNull(ac); + Assert.False(fx.isDefault); + + var layer = ac.layers.FirstOrDefault(l => l.name == layerName); + Assert.NotNull(layer); + return layer; + } } } \ No newline at end of file diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_BaseFX.controller.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller similarity index 97% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller index 21432d02..254e7ee2 100644 --- a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller +++ b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller @@ -7,7 +7,7 @@ AnimatorStateMachine: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Base Layer + m_Name: child_controller m_ChildStates: - serializedVersion: 1 m_State: {fileID: 4610933037596458320} @@ -33,7 +33,7 @@ AnimatorController: m_AnimatorParameters: [] m_AnimatorLayers: - serializedVersion: 5 - m_Name: Base Layer + m_Name: child_controller m_StateMachine: {fileID: -7544367895585285567} m_Mask: {fileID: 0} m_Motions: [] diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_ChildController.controller.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Empty.anim.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Rotate.anim.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TMTSO_Toggle.anim.meta diff --git a/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs new file mode 100644 index 00000000..5f97151c --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs @@ -0,0 +1,27 @@ +using nadena.dev.modular_avatar.core.editor; +using NUnit.Framework; +using UnityEditor; +using UnityEngine; + +namespace modular_avatar_tests.TransformMappingThroughSwitchedObject +{ + /// + /// This test verifies that transform mappings are properly handled, even if the bone they target is on an armature + /// underneath multiple switched objects (which therefore would generate multiple levels of proxy switch objects). + /// + public class TransformMappingThroughSwitchedObject : TestBase + { + [Test] + public void TransformMappingHandledCorrectly() + { + var prefab = CreatePrefab("TransformMappingThroughSwitchedObject.prefab"); + AvatarProcessor.ProcessAvatar(prefab); + + var motion = findFxMotion(prefab, "child_controller"); + + var binding = EditorCurveBinding.FloatCurve("Armature/Hips", typeof(Transform), "localEulerAnglesRaw.x"); + var curve = AnimationUtility.GetEditorCurve(motion, binding); + Assert.IsNotNull(curve); + } + } +} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs.meta new file mode 100644 index 00000000..486ec8bb --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: baeea9019e894fb09d9b25f015856348 +timeCreated: 1673016399 \ No newline at end of file diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab diff --git a/Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab.meta b/Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab.meta rename to Assets/_ModularAvatar/EditModeTests/TransformMappingThroughSwitchedObject/TransformMappingThroughSwitchedObject.prefab.meta