A game about forced loneliness, made by TACStudios
1namespace Unity.VisualScripting 2{ 3 [TypeIcon(typeof(StateGraph))] 4 [UnitCategory("Nesting")] 5 public sealed class StateUnit : NesterUnit<StateGraph, StateGraphAsset> 6 { 7 public StateUnit() : base() { } 8 9 public StateUnit(StateGraphAsset macro) : base(macro) { } 10 11 /// <summary> 12 /// The entry point to start the state graph. 13 /// </summary> 14 [DoNotSerialize] 15 public ControlInput start { get; private set; } 16 17 /// <summary> 18 /// The entry point to stop the state graph. 19 /// </summary> 20 [DoNotSerialize] 21 public ControlInput stop { get; private set; } 22 23 /// <summary> 24 /// The action to execute after the state graph has been started. 25 /// </summary> 26 [DoNotSerialize] 27 public ControlOutput started { get; private set; } 28 29 /// <summary> 30 /// The action to execute after the state graph has been stopped. 31 /// </summary> 32 [DoNotSerialize] 33 public ControlOutput stopped { get; private set; } 34 35 public static StateUnit WithStart() 36 { 37 var stateUnit = new StateUnit(); 38 stateUnit.nest.source = GraphSource.Embed; 39 stateUnit.nest.embed = StateGraph.WithStart(); 40 return stateUnit; 41 } 42 43 protected override void Definition() 44 { 45 start = ControlInput(nameof(start), Start); 46 stop = ControlInput(nameof(stop), Stop); 47 48 started = ControlOutput(nameof(started)); 49 stopped = ControlOutput(nameof(stopped)); 50 51 Succession(start, started); 52 Succession(stop, stopped); 53 } 54 55 private ControlOutput Start(Flow flow) 56 { 57 flow.stack.EnterParentElement(this); 58 nest.graph.Start(flow); 59 flow.stack.ExitParentElement(); 60 return started; 61 } 62 63 private ControlOutput Stop(Flow flow) 64 { 65 flow.stack.EnterParentElement(this); 66 nest.graph.Stop(flow); 67 flow.stack.ExitParentElement(); 68 return stopped; 69 } 70 71 public override StateGraph DefaultGraph() 72 { 73 return StateGraph.WithStart(); 74 } 75 } 76}