A game about forced loneliness, made by TACStudios
1using UnityObject = UnityEngine.Object; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Branches flow depending on whether the input is null. 7 /// </summary> 8 [UnitCategory("Nulls")] 9 [TypeIcon(typeof(Null))] 10 public sealed class NullCheck : Unit 11 { 12 /// <summary> 13 /// The input. 14 /// </summary> 15 [DoNotSerialize] 16 [PortLabelHidden] 17 public ValueInput input { get; private set; } 18 19 /// <summary> 20 /// The entry point for the null check. 21 /// </summary> 22 [DoNotSerialize] 23 [PortLabelHidden] 24 public ControlInput enter { get; private set; } 25 26 /// <summary> 27 /// The action to execute if the input is not null. 28 /// </summary> 29 [DoNotSerialize] 30 [PortLabel("Not Null")] 31 public ControlOutput ifNotNull { get; private set; } 32 33 /// <summary> 34 /// The action to execute if the input is null. 35 /// </summary> 36 [DoNotSerialize] 37 [PortLabel("Null")] 38 public ControlOutput ifNull { get; private set; } 39 40 protected override void Definition() 41 { 42 enter = ControlInput(nameof(enter), Enter); 43 input = ValueInput<object>(nameof(input)).AllowsNull(); 44 ifNotNull = ControlOutput(nameof(ifNotNull)); 45 ifNull = ControlOutput(nameof(ifNull)); 46 47 Requirement(input, enter); 48 Succession(enter, ifNotNull); 49 Succession(enter, ifNull); 50 } 51 52 public ControlOutput Enter(Flow flow) 53 { 54 var input = flow.GetValue(this.input); 55 56 bool isNull; 57 58 if (input is UnityObject) 59 { 60 // Required cast because of Unity's custom == operator. 61 // ReSharper disable once ConditionIsAlwaysTrueOrFalse 62 isNull = (UnityObject)input == null; 63 } 64 else 65 { 66 isNull = input == null; 67 } 68 69 if (isNull) 70 { 71 return ifNull; 72 } 73 else 74 { 75 return ifNotNull; 76 } 77 } 78 } 79}