Firstborn/Library/PackageCache/com.unity.visualscripting@1.../Runtime/VisualScripting.State/AnyState.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2023-03-28 13:24:16 -04:00
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);
}
}
}
}
}