A game about forced loneliness, made by TACStudios
1namespace Unity.VisualScripting 2{ 3 /// <summary> 4 /// Executes an action only once, and a different action afterwards. 5 /// </summary> 6 [UnitCategory("Control")] 7 [UnitOrder(14)] 8 public sealed class Once : Unit, IGraphElementWithData 9 { 10 public sealed class Data : IGraphElementData 11 { 12 public bool executed; 13 } 14 15 /// <summary> 16 /// The entry point for the action. 17 /// </summary> 18 [DoNotSerialize] 19 [PortLabelHidden] 20 public ControlInput enter { get; private set; } 21 22 /// <summary> 23 /// Trigger to reset the once check. 24 /// </summary> 25 [DoNotSerialize] 26 public ControlInput reset { get; private set; } 27 28 /// <summary> 29 /// The action to execute the first time the node is entered. 30 /// </summary> 31 [DoNotSerialize] 32 public ControlOutput once { get; private set; } 33 34 /// <summary> 35 /// The action to execute subsequently. 36 /// </summary> 37 [DoNotSerialize] 38 public ControlOutput after { get; private set; } 39 40 protected override void Definition() 41 { 42 enter = ControlInput(nameof(enter), Enter); 43 reset = ControlInput(nameof(reset), Reset); 44 once = ControlOutput(nameof(once)); 45 after = ControlOutput(nameof(after)); 46 47 Succession(enter, once); 48 Succession(enter, after); 49 } 50 51 public IGraphElementData CreateData() 52 { 53 return new Data(); 54 } 55 56 public ControlOutput Enter(Flow flow) 57 { 58 var data = flow.stack.GetElementData<Data>(this); 59 60 if (!data.executed) 61 { 62 data.executed = true; 63 64 return once; 65 } 66 else 67 { 68 return after; 69 } 70 } 71 72 public ControlOutput Reset(Flow flow) 73 { 74 flow.stack.GetElementData<Data>(this).executed = false; 75 76 return null; 77 } 78 } 79}