Maze / Library /PackageCache /com.unity.visualscripting@1.8.0 /Runtime /VisualScripting.Flow /Framework /Nulls /NullCheck.cs
| using UnityObject = UnityEngine.Object; | |
| namespace Unity.VisualScripting | |
| { | |
| /// <summary> | |
| /// Branches flow depending on whether the input is null. | |
| /// </summary> | |
| [] | |
| [] | |
| public sealed class NullCheck : Unit | |
| { | |
| /// <summary> | |
| /// The input. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueInput input { get; private set; } | |
| /// <summary> | |
| /// The entry point for the null check. | |
| /// </summary> | |
| [] | |
| [] | |
| public ControlInput enter { get; private set; } | |
| /// <summary> | |
| /// The action to execute if the input is not null. | |
| /// </summary> | |
| [] | |
| [] | |
| public ControlOutput ifNotNull { get; private set; } | |
| /// <summary> | |
| /// The action to execute if the input is null. | |
| /// </summary> | |
| [] | |
| [] | |
| public ControlOutput ifNull { get; private set; } | |
| protected override void Definition() | |
| { | |
| enter = ControlInput(nameof(enter), Enter); | |
| input = ValueInput<object>(nameof(input)).AllowsNull(); | |
| ifNotNull = ControlOutput(nameof(ifNotNull)); | |
| ifNull = ControlOutput(nameof(ifNull)); | |
| Requirement(input, enter); | |
| Succession(enter, ifNotNull); | |
| Succession(enter, ifNull); | |
| } | |
| public ControlOutput Enter(Flow flow) | |
| { | |
| var input = flow.GetValue(this.input); | |
| bool isNull; | |
| if (input is UnityObject) | |
| { | |
| // Required cast because of Unity's custom == operator. | |
| // ReSharper disable once ConditionIsAlwaysTrueOrFalse | |
| isNull = (UnityObject)input == null; | |
| } | |
| else | |
| { | |
| isNull = input == null; | |
| } | |
| if (isNull) | |
| { | |
| return ifNull; | |
| } | |
| else | |
| { | |
| return ifNotNull; | |
| } | |
| } | |
| } | |
| } | |