File size: 1,830 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Checks whether a variable is defined.
/// </summary>
[UnitTitle("Has Variable")]
public sealed class IsVariableDefined : UnifiedVariableUnit
{
/// <summary>
/// Whether the variable is defined.
/// </summary>
[DoNotSerialize]
[PortLabel("Defined")]
[PortLabelHidden]
[PortKey("isDefined")]
public ValueOutput isVariableDefined { get; private set; }
protected override void Definition()
{
base.Definition();
isVariableDefined = ValueOutput("isDefined", IsDefined);
Requirement(name, isVariableDefined);
if (kind == VariableKind.Object)
{
Requirement(@object, isVariableDefined);
}
}
private bool IsDefined(Flow flow)
{
var name = flow.GetValue<string>(this.name);
switch (kind)
{
case VariableKind.Flow:
return flow.variables.IsDefined(name);
case VariableKind.Graph:
return Variables.Graph(flow.stack).IsDefined(name);
case VariableKind.Object:
return Variables.Object(flow.GetValue<GameObject>(@object)).IsDefined(name);
case VariableKind.Scene:
return Variables.Scene(flow.stack.scene).IsDefined(name);
case VariableKind.Application:
return Variables.Application.IsDefined(name);
case VariableKind.Saved:
return Variables.Saved.IsDefined(name);
default:
throw new UnexpectedEnumValueException<VariableKind>(kind);
}
}
}
}
|