From 0ff1da073419c6324fe1e15adaaef22e7e38c33d Mon Sep 17 00:00:00 2001 From: bd_ Date: Sat, 9 Mar 2024 01:55:31 -0800 Subject: [PATCH] fix: type corrections not applied to substatemachine exit transitions (#751) Closes: #748 --- Editor/Animation/AnimatorCombiner.cs | 21 ++++++++++++++++-- .../TypeAdjustment/ConvertTransitionTypes.cs | 17 ++++++++++++++ .../TypeAdjustment/ac1.controller | 22 ++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Editor/Animation/AnimatorCombiner.cs b/Editor/Animation/AnimatorCombiner.cs index 419de050..2b83849d 100644 --- a/Editor/Animation/AnimatorCombiner.cs +++ b/Editor/Animation/AnimatorCombiner.cs @@ -22,10 +22,13 @@ * SOFTWARE. */ +#region + using System; using System.Collections.Generic; using System.Linq; using nadena.dev.modular_avatar.editor.ErrorReporting; +using nadena.dev.ndmf; using nadena.dev.ndmf.util; using UnityEditor; using UnityEditor.Animations; @@ -37,11 +40,13 @@ using VRC.SDK3.Avatars.Components; using VRC.SDKBase; #endif +#endregion + namespace nadena.dev.modular_avatar.animation { internal class AnimatorCombiner { - private readonly ndmf.BuildContext _context; + private readonly BuildContext _context; private readonly AnimatorController _combined; private readonly DeepClone _deepClone; @@ -68,7 +73,7 @@ namespace nadena.dev.modular_avatar.animation public VRC_AnimatorLayerControl.BlendableLayer? BlendableLayer; #endif - public AnimatorCombiner(ndmf.BuildContext context, String assetName) + public AnimatorCombiner(BuildContext context, String assetName) { _combined = new AnimatorController(); if (context.AssetContainer != null && EditorUtility.IsPersistent(context.AssetContainer)) @@ -141,6 +146,18 @@ namespace nadena.dev.modular_avatar.animation .SelectMany(FixupTransition).ToArray(); asm.anyStateTransitions = asm.anyStateTransitions .SelectMany(FixupTransition).ToArray(); + + foreach (var stateMachine in asm.stateMachines) + { + var ssm = stateMachine.stateMachine; + + var stateMachineTransitions = asm.GetStateMachineTransitions(ssm); + if (stateMachineTransitions.Length > 0) + { + asm.SetStateMachineTransitions(ssm, + stateMachineTransitions.SelectMany(FixupTransition).ToArray()); + } + } } } } diff --git a/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs b/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs index a8ef66b9..0161235d 100644 --- a/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs +++ b/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs @@ -180,6 +180,23 @@ public class ConvertTransitionTypes : TestBase AssertTransitions(layer, "int", "eq1", 0, ("int", AnimatorConditionMode.Equals, 1f)); } + [Test] + public void SubStateMachineExitTransitions() + { + var prefab = CreatePrefab("ConvertTransitionTypes.prefab"); + + AvatarProcessor.ProcessAvatar(prefab); + + var layer = findFxLayer(prefab, "sub_state_machine"); + + var rootStateMachine = layer.stateMachine; + var ssm1 = layer.stateMachine.stateMachines[0].stateMachine; + var exitTransitions = rootStateMachine.GetStateMachineTransitions(ssm1); + + AssertSingleTransition(exitTransitions[0], ("int", AnimatorConditionMode.Greater, 0.1f)); + AssertSingleTransition(exitTransitions[1], ("int", AnimatorConditionMode.Less, -0.1f)); + } + [Test] public void CrossLayerTypeConsistency() { diff --git a/UnitTests~/MergeAnimatorTests/TypeAdjustment/ac1.controller b/UnitTests~/MergeAnimatorTests/TypeAdjustment/ac1.controller index 42d2465f..ba04b0c9 100644 --- a/UnitTests~/MergeAnimatorTests/TypeAdjustment/ac1.controller +++ b/UnitTests~/MergeAnimatorTests/TypeAdjustment/ac1.controller @@ -506,6 +506,23 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1109 &-1214348927005070382 +AnimatorTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 7 + m_ConditionEvent: int + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 0} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 1 + serializedVersion: 1 --- !u!91 &9100000 AnimatorController: m_ObjectHideFlags: 0 @@ -1034,7 +1051,10 @@ AnimatorStateMachine: - {fileID: 1712637675519008892} m_EntryTransitions: - {fileID: 6284330602530841453} - m_StateMachineTransitions: {} + m_StateMachineTransitions: + - first: {fileID: -2155158836370751539} + second: + - {fileID: -1214348927005070382} m_StateMachineBehaviours: [] m_AnyStatePosition: {x: 50, y: 20, z: 0} m_EntryPosition: {x: 50, y: 120, z: 0}