A game about forced loneliness, made by TACStudios
1using System; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Throws an exception. 7 /// </summary> 8 [UnitCategory("Control")] 9 [UnitOrder(16)] 10 public sealed class Throw : Unit 11 { 12 /// <summary> 13 /// Whether a custom exception object should be specified manually. 14 /// </summary> 15 [Serialize] 16 [Inspectable, UnitHeaderInspectable("Custom")] 17 [InspectorToggleLeft] 18 public bool custom { get; set; } 19 20 /// <summary> 21 /// The entry point to throw the exception. 22 /// </summary> 23 [DoNotSerialize] 24 [PortLabelHidden] 25 public ControlInput enter { get; private set; } 26 27 /// <summary> 28 /// The message of the exception. 29 /// </summary> 30 [DoNotSerialize] 31 public ValueInput message { get; private set; } 32 33 /// <summary> 34 /// The exception to throw. 35 /// </summary> 36 [DoNotSerialize] 37 public ValueInput exception { get; private set; } 38 39 protected override void Definition() 40 { 41 if (custom) 42 { 43 enter = ControlInput(nameof(enter), ThrowCustom); 44 exception = ValueInput<Exception>(nameof(exception)); 45 Requirement(exception, enter); 46 } 47 else 48 { 49 enter = ControlInput(nameof(enter), ThrowMessage); 50 message = ValueInput(nameof(message), string.Empty); 51 Requirement(message, enter); 52 } 53 } 54 55 private ControlOutput ThrowCustom(Flow flow) 56 { 57 throw flow.GetValue<Exception>(exception); 58 } 59 60 private ControlOutput ThrowMessage(Flow flow) 61 { 62 throw new Exception(flow.GetValue<string>(message)); 63 } 64 } 65}