From 01724155b051f83e26b43c60a86029eab95631c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Mon, 19 Aug 2024 01:40:08 +0200 Subject: [PATCH] Fix Any state transitions will be created from SSMs: - Due to an implementation error, creating Any state transitions previously did not have any effect in the graph. - This now creates Any state from the root machine. - Sub-state machines "cannot" have Any state transitions created directly from them. - Internally, Any always comes from the root state machine, but visually in the graph, it will come from the sub-state machine. --- .../V1/Editor/AacAnimatorNode.cs | 8 ++++++++ .../V1/Editor/AacFlStates.cs | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacAnimatorNode.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacAnimatorNode.cs index 3909bf2..afd137d 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacAnimatorNode.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacAnimatorNode.cs @@ -23,6 +23,14 @@ namespace AnimatorAsCode.V1 AnimatorRoot = animatorRoot; } + internal AacFlStateMachine RootMachine() + { + if (ParentMachine != null) return ParentMachine.RootMachine(); + if (this is AacFlStateMachine root) + return root; + return null; + } + /// Move the node the left of the other node in the graph. public TNode LeftOf(AacAnimatorNode otherNode) => MoveNextTo(otherNode, -1, 0); diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlStates.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlStates.cs index a340cbe..c0c63e7 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlStates.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlStates.cs @@ -226,7 +226,9 @@ namespace AnimatorAsCode.V1 /// Create a transition from Any to the `destination` state. public AacFlTransition AnyTransitionsTo(AacFlState destination) { - return AnyTransition(destination, Machine); + // Sub-state machines "cannot" have Any state transitions created directly from them. + // Internally, Any always comes from the root state machine, but visually in the graph, it will come from the sub-state machine. + return AnyTransition(destination, RootMachine().Machine); } /// Create a transition from Any to the `destination` state machine. @@ -401,7 +403,10 @@ namespace AnimatorAsCode.V1 /// Create a new transition from Any to this state. public AacFlTransition TransitionsFromAny() { - return new AacFlTransition(ConfigureTransition(AacInternals.NoUndo(State, () => _machine.AddAnyStateTransition(State))), _machine, null, State); + // Sub-state machines "cannot" have Any state transitions created directly from them. + // Internally, Any always comes from the root state machine, but visually in the graph, it will come from the sub-state machine. + var rootMachine = RootMachine().Machine; + return new AacFlTransition(ConfigureTransition(AacInternals.NoUndo(State, () => rootMachine.AddAnyStateTransition(State))), rootMachine, null, State); } /// Create a new transition from Entry to this state. Note that the first created state is the default state, so generally this function does not need to be invoked onto the first created state.