| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Currently still a work in progress and subject to breaking changes. Visual State Machine is a Unity package designed to simplify the creation and management of state machines in Unity projects. It provides a visual editor for designing state machines, making it easier to create complex behaviors without writing extensive code.
To install Visual State Machine in your Unity project, follow these steps:
When upgrading to Visual State Machine V2 (VSM2) version 0.9.0-beta, follow these steps to ensure a seamless transition and maintain functionality within your Unity project:
[NodeWidth(width:190), NodeColor(NodeColor.Teal), NodeIcon(NodeIcon.Clock)]
public class DelayState : BaseDelayState
{
[Transition(frameDelay:0)]
public event Action OnComplete;
[NonSerialized]
private float _elapsedTime;
[Enter]
public override void OnEnter()
{
_elapsedTime = 0f;
}
public override void OnUpdate()
{
_elapsedTime += Time.deltaTime;
if (_elapsedTime < Duration) return;
OnComplete?.Invoke();
}
}To pass data between states in the Visual State Machine, you utilize transitions. Transitions are defined by public event Actions that are decorated with a TransitionAttribute [Transition]. Here's how you can effectively use typed transitions:
Basic Transitions
Typed Transitions
public class SourceState : State
{
[Transition]
public event Action<int> OnTransitionWithInt;
public void TriggerTransition()
{
int valueToPass = 42;
OnTransitionWithInt?.Invoke(valueToPass);
}
[Enter]
public void OnEnter()
{
// Initialization logic
}
}public class TargetState : State
{
[Enter]
public void OnEnterWithInt(int receivedValue)
{
Debug.Log($"Received value: {receivedValue}");
}
}public class MultiplyState : State
{
[Transition]
public event Action<float> OnCompleteWithResult;
[SerializeField]
private float _multiplyBy = 2;
[Enter]
public void OnEnterWithFloat(float value)
{
var result = value * _multiplyBy;
OnCompleteWithResult?.Invoke(result);
}
}public class ResultState : State
{
[Enter]
public void OnEnterWithResult(float result)
{
Debug.Log($"Received result: {result}");
}
}By following this approach, you can effectively pass data between states in your Visual State Machine, enhancing the flexibility and functionality of your state-driven behaviors.
Add JumpOutState state and set it's Id. Then create a JumpInState with the corresponding Id to jump from one node to another.
Looping.mp4The process of transitioning between nodes originally incurred no delay at all but when wiring up a looping state machine it could cause a stack overflow. To prevent this a delay of 1 frame has been added to all transitions by default, but this can be configured on a per transition bases by passing a frameDelay value through the Transition attribute, but please use with caution as a frameDelay of 0 can cause a stack overflow.
The State Machine Editor supports copy and paste within and between state machines.
CopyAndPaste.mp4States have access to a shared data store
public class StateOne : State
{
[Transition] public event Action OnComplete;
[Enter]
public override void OnEnter()
{
SharedData.SetData("age", 42);
OnComplete?.Invoke();
}
}
public class StateTwo : State
{
[Transition] public event Action OnComplete;
[Enter]
public override void OnEnter()
{
var age = SharedData.GetData<int>("age");
Debug.Log($"StateTwo - Age:{age}");
OnComplete?.Invoke();
}
}This same data store is exposed externally to the state machine through the StateMachineController.SharedData
VisualStateMachineV2 is licensed under the MIT license
| Back | FazBrowse Home | New Git URL |