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

StateMachine.cs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. namespace Unity.VisualScripting
  3. {
  4. [AddComponentMenu("Visual Scripting/State Machine")]
  5. [RequireComponent(typeof(Variables))]
  6. [DisableAnnotation]
  7. [HelpURL("https://docs.unity3d.com/Packages/com.unity.visualscripting@latest/index.html?subfolder=/manual/vs-graphs-machines-macros.html")]
  8. public sealed class StateMachine : EventMachine<StateGraph, StateGraphAsset>
  9. {
  10. protected override void OnEnable()
  11. {
  12. if (hasGraph)
  13. {
  14. using (var flow = Flow.New(reference))
  15. {
  16. graph.Start(flow);
  17. }
  18. }
  19. base.OnEnable();
  20. }
  21. protected override void OnInstantiateWhileEnabled()
  22. {
  23. if (hasGraph)
  24. {
  25. using (var flow = Flow.New(reference))
  26. {
  27. graph.Start(flow);
  28. }
  29. }
  30. base.OnInstantiateWhileEnabled();
  31. }
  32. protected override void OnUninstantiateWhileEnabled()
  33. {
  34. base.OnUninstantiateWhileEnabled();
  35. if (hasGraph)
  36. {
  37. using (var flow = Flow.New(reference))
  38. {
  39. graph.Stop(flow);
  40. }
  41. }
  42. }
  43. protected override void OnDisable()
  44. {
  45. base.OnDisable();
  46. if (hasGraph)
  47. {
  48. using (var flow = Flow.New(reference))
  49. {
  50. graph.Stop(flow);
  51. }
  52. }
  53. }
  54. [ContextMenu("Show Data...")]
  55. protected override void ShowData()
  56. {
  57. base.ShowData();
  58. }
  59. public override StateGraph DefaultGraph()
  60. {
  61. return StateGraph.WithStart();
  62. }
  63. }
  64. }