A game about forced loneliness, made by TACStudios
1#pragma warning disable 618 2 3namespace Unity.VisualScripting 4{ 5 [UnitShortTitle("Set Variable")] 6 public abstract class SetVariableUnit : VariableUnit 7 { 8 protected SetVariableUnit() : base() { } 9 10 protected SetVariableUnit(string defaultName) : base(defaultName) { } 11 12 /// <summary> 13 /// The entry point to assign the variable reference. 14 /// </summary> 15 [DoNotSerialize] 16 [PortLabelHidden] 17 public ControlInput assign { get; set; } 18 19 /// <summary> 20 /// The value to assign to the variable. 21 /// </summary> 22 [DoNotSerialize] 23 [PortLabel("New Value")] 24 [PortLabelHidden] 25 public ValueInput input { get; private set; } 26 27 /// <summary> 28 /// The action to execute once the variable has been assigned. 29 /// </summary> 30 [DoNotSerialize] 31 [PortLabelHidden] 32 public ControlOutput assigned { get; set; } 33 34 /// <summary> 35 /// The value assigned to the variable. 36 /// </summary> 37 [DoNotSerialize] 38 [PortLabel("Value")] 39 [PortLabelHidden] 40 public ValueOutput output { get; private set; } 41 42 protected override void Definition() 43 { 44 base.Definition(); 45 46 assign = ControlInput(nameof(assign), Assign); 47 input = ValueInput<object>(nameof(input)); 48 output = ValueOutput<object>(nameof(output)); 49 assigned = ControlOutput(nameof(assigned)); 50 51 Requirement(input, assign); 52 Requirement(name, assign); 53 Assignment(assign, output); 54 Succession(assign, assigned); 55 } 56 57 protected virtual ControlOutput Assign(Flow flow) 58 { 59 var input = flow.GetValue<object>(this.input); 60 var name = flow.GetValue<string>(this.name); 61 62 GetDeclarations(flow).Set(name, input); 63 64 flow.SetValue(output, input); 65 66 return assigned; 67 } 68 } 69}