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.
This commit is contained in:
Haï~
2024-08-19 01:40:08 +02:00
parent 4c50d8876e
commit 01724155b0
2 changed files with 15 additions and 2 deletions
@@ -23,6 +23,14 @@ namespace AnimatorAsCode.V1
AnimatorRoot = animatorRoot; 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. /// Move the node the left of the other node in the graph.
public TNode LeftOf(AacAnimatorNode otherNode) => MoveNextTo(otherNode, -1, 0); public TNode LeftOf(AacAnimatorNode otherNode) => MoveNextTo(otherNode, -1, 0);
@@ -226,7 +226,9 @@ namespace AnimatorAsCode.V1
/// Create a transition from Any to the `destination` state. /// Create a transition from Any to the `destination` state.
public AacFlTransition AnyTransitionsTo(AacFlState destination) 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. /// 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. /// Create a new transition from Any to this state.
public AacFlTransition TransitionsFromAny() 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.<br/> /// 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.<br/>