diff --git a/Editor/PluginDefinition/PluginDefinition.cs b/Editor/PluginDefinition/PluginDefinition.cs index b73e5a32..742a1e17 100644 --- a/Editor/PluginDefinition/PluginDefinition.cs +++ b/Editor/PluginDefinition/PluginDefinition.cs @@ -7,6 +7,7 @@ using nadena.dev.modular_avatar.editor.ErrorReporting; using nadena.dev.ndmf; using nadena.dev.ndmf.animator; using nadena.dev.ndmf.fluent; +using nadena.dev.ndmf.util; using UnityEngine; using Object = UnityEngine.Object; @@ -76,6 +77,8 @@ namespace nadena.dev.modular_avatar.core.editor.plugin #endif seq.Run(MergeArmaturePluginPass.Instance); + seq.Run("Prune empty animator layers", + ctx => { ctx.Extension().RemoveEmptyLayers(); }); }); seq.WithRequiredExtension(typeof(AnimationServicesContext), _s2 => diff --git a/UnitTests~/Animation/LayerPruningTest.cs b/UnitTests~/Animation/LayerPruningTest.cs index c5af1638..40cd179c 100644 --- a/UnitTests~/Animation/LayerPruningTest.cs +++ b/UnitTests~/Animation/LayerPruningTest.cs @@ -32,8 +32,12 @@ namespace modular_avatar_tests Assert.AreEqual("L3", l3.name); Assert.AreEqual("L3.a", l3a.name); - Assert.AreEqual(2, l3.stateMachine.defaultState.behaviours.Length); - Assert.AreEqual(4, ((VRCAnimatorLayerControl)l3.stateMachine.defaultState.behaviours[0]).layer); + // The layer control behavior referencing the deleted layer should be removed + Assert.AreEqual(3, l3.stateMachine.defaultState.behaviours.Length); + Assert.AreEqual("2", ((VRCAnimatorLayerControl)l3.stateMachine.defaultState.behaviours[0]).debugString); + Assert.IsTrue(l3.stateMachine.defaultState.behaviours[1] is VRCAnimatorTrackingControl); + Assert.AreEqual("3", ((VRCAnimatorLayerControl)l3.stateMachine.defaultState.behaviours[2]).debugString); + Assert.AreEqual(3, ((VRCAnimatorLayerControl)l3.stateMachine.defaultState.behaviours[0]).layer); Assert.AreEqual(1, l3a.stateMachine.defaultState.behaviours.Length); Assert.AreEqual(3, ((VRCAnimatorLayerControl)l3a.stateMachine.defaultState.behaviours[0]).layer); diff --git a/UnitTests~/Animation/LayerPruningTest/AC3.controller b/UnitTests~/Animation/LayerPruningTest/AC3.controller index 4df78521..0f9264ba 100644 --- a/UnitTests~/Animation/LayerPruningTest/AC3.controller +++ b/UnitTests~/Animation/LayerPruningTest/AC3.controller @@ -1,5 +1,22 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!114 &-8943217745761122886 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -1936262289, guid: 67cc4cb7839cd3741b63733d5adf0442, type: 3} + m_Name: + m_EditorClassIdentifier: + playable: 0 + layer: 0 + goalWeight: 0 + blendDuration: 0 + debugString: 3 --- !u!1107 &-6599268793956612610 AnimatorStateMachine: serializedVersion: 6 @@ -76,6 +93,7 @@ AnimatorState: - {fileID: 2645212092703721488} - {fileID: -4263003778027536188} - {fileID: 1637143755065747004} + - {fileID: -8943217745761122886} m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 m_WriteDefaultValues: 1 @@ -102,8 +120,8 @@ MonoBehaviour: m_Script: {fileID: -1936262289, guid: 67cc4cb7839cd3741b63733d5adf0442, type: 3} m_Name: m_EditorClassIdentifier: - playable: 0 - layer: 0 + playable: 1 + layer: 1 goalWeight: 0 blendDuration: 0 debugString: 2