A game about forced loneliness, made by TACStudios
1using System.ComponentModel; 2using UnityEngine; 3 4namespace Unity.VisualScripting 5{ 6 [SerializationVersion("A")] 7 [TypeIcon(typeof(FlowGraph))] 8 [DisplayName("Script State")] 9 public sealed class FlowState : NesterState<FlowGraph, ScriptGraphAsset>, IGraphEventListener 10 { 11 public FlowState() { } 12 13 public FlowState(ScriptGraphAsset macro) : base(macro) { } 14 15 16 #region Lifecycle 17 18 protected override void OnEnterImplementation(Flow flow) 19 { 20 if (flow.stack.TryEnterParentElement(this)) 21 { 22 nest.graph.StartListening(flow.stack); 23 flow.stack.TriggerEventHandler(hook => hook == StateEventHooks.OnEnterState, new EmptyEventArgs(), parent => parent is SubgraphUnit, false); 24 flow.stack.ExitParentElement(); 25 } 26 } 27 28 protected override void OnExitImplementation(Flow flow) 29 { 30 if (flow.stack.TryEnterParentElement(this)) 31 { 32 flow.stack.TriggerEventHandler(hook => hook == StateEventHooks.OnExitState, new EmptyEventArgs(), parent => parent is SubgraphUnit, false); 33 nest.graph.StopListening(flow.stack); 34 flow.stack.ExitParentElement(); 35 } 36 } 37 38 public void StartListening(GraphStack stack) 39 { 40 if (stack.TryEnterParentElement(this)) 41 { 42 nest.graph.StartListening(stack); 43 stack.ExitParentElement(); 44 } 45 } 46 47 public void StopListening(GraphStack stack) 48 { 49 if (stack.TryEnterParentElement(this)) 50 { 51 nest.graph.StopListening(stack); 52 stack.ExitParentElement(); 53 } 54 } 55 56 public bool IsListening(GraphPointer pointer) 57 { 58 return pointer.GetElementData<Data>(this).isActive; 59 } 60 61 #endregion 62 63 64 #region Factory 65 66 public override FlowGraph DefaultGraph() 67 { 68 return GraphWithEnterUpdateExit(); 69 } 70 71 public static FlowState WithEnterUpdateExit() 72 { 73 var flowState = new FlowState(); 74 flowState.nest.source = GraphSource.Embed; 75 flowState.nest.embed = GraphWithEnterUpdateExit(); 76 return flowState; 77 } 78 79 public static FlowGraph GraphWithEnterUpdateExit() 80 { 81 return new FlowGraph 82 { 83 units = 84 { 85 new OnEnterState { position = new Vector2(-205, -215) }, 86 new Update { position = new Vector2(-161, -38) }, 87 new OnExitState { position = new Vector2(-205, 145) } 88 } 89 }; 90 } 91 92 #endregion 93 } 94}