A game about forced loneliness, made by TACStudios
1using System.Linq; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Fetches input values from the parent super unit for this graph. 7 /// </summary> 8 [UnitCategory("Nesting")] 9 [UnitOrder(1)] 10 [UnitTitle("Input")] 11 public sealed class GraphInput : Unit 12 { 13 public override bool canDefine => graph != null; 14 15 protected override void Definition() 16 { 17 isControlRoot = true; 18 19 foreach (var controlInputDefinition in graph.validPortDefinitions.OfType<ControlInputDefinition>()) 20 { 21 ControlOutput(controlInputDefinition.key); 22 } 23 24 foreach (var valueInputDefinition in graph.validPortDefinitions.OfType<ValueInputDefinition>()) 25 { 26 var key = valueInputDefinition.key; 27 var type = valueInputDefinition.type; 28 29 ValueOutput(type, key, (flow) => 30 { 31 var superUnit = flow.stack.GetParent<SubgraphUnit>(); 32 33 if (flow.enableDebug) 34 { 35 var editorData = flow.stack.GetElementDebugData<IUnitDebugData>(superUnit); 36 37 editorData.lastInvokeFrame = EditorTimeBinding.frame; 38 editorData.lastInvokeTime = EditorTimeBinding.time; 39 } 40 41 flow.stack.ExitParentElement(); 42 superUnit.EnsureDefined(); 43 var value = flow.GetValue(superUnit.valueInputs[key], type); 44 flow.stack.EnterParentElement(superUnit); 45 46 return value; 47 }); 48 } 49 } 50 51 protected override void AfterDefine() 52 { 53 graph.onPortDefinitionsChanged += Define; 54 } 55 56 protected override void BeforeUndefine() 57 { 58 graph.onPortDefinitionsChanged -= Define; 59 } 60 } 61}