You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
C#

1 year ago
namespace Unity.VisualScripting
{
/// <summary>
/// A special state that can trigger transitions to other states,
/// no matter which state is currently active. This state cannot receive
/// transitions.
/// </summary>
public sealed class AnyState : State
{
[DoNotSerialize]
public override bool canBeDestination => false;
public AnyState() : base()
{
isStart = true;
}
public override void OnExit(Flow flow, StateExitReason reason)
{
// Don't exit this state from branching.
if (reason == StateExitReason.Branch)
{
return;
}
base.OnExit(flow, reason);
}
public override void OnBranchTo(Flow flow, IState destination)
{
// Before entering the destination destination state,
// exit all other connected states.
foreach (var outgoingTransition in outgoingTransitionsNoAlloc)
{
if (outgoingTransition.destination != destination)
{
outgoingTransition.destination.OnExit(flow, StateExitReason.AnyBranch);
}
}
}
}
}