testss
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a null value.
|
||||
/// </summary>
|
||||
[UnitCategory("Nulls")]
|
||||
public sealed class Null : Unit
|
||||
{
|
||||
/// <summary>
|
||||
/// A null value.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
public ValueOutput @null { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
@null = ValueOutput<object>(nameof(@null), (recursion) => null).Predictable();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Branches flow depending on whether the input is null.
|
||||
/// </summary>
|
||||
[UnitCategory("Nulls")]
|
||||
[TypeIcon(typeof(Null))]
|
||||
public sealed class NullCheck : Unit
|
||||
{
|
||||
/// <summary>
|
||||
/// The input.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ValueInput input { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The entry point for the null check.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ControlInput enter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The action to execute if the input is not null.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Not Null")]
|
||||
public ControlOutput ifNotNull { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The action to execute if the input is null.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Null")]
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a fallback value if the input value is null.
|
||||
/// </summary>
|
||||
[UnitCategory("Nulls")]
|
||||
[TypeIcon(typeof(Null))]
|
||||
public sealed class NullCoalesce : Unit
|
||||
{
|
||||
/// <summary>
|
||||
/// The value.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
public ValueInput input { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The fallback to use if the value is null.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
public ValueInput fallback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The returned value.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ValueOutput result { get; private set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
input = ValueInput<object>(nameof(input)).AllowsNull();
|
||||
fallback = ValueInput<object>(nameof(fallback));
|
||||
result = ValueOutput(nameof(result), Coalesce).Predictable();
|
||||
|
||||
Requirement(input, result);
|
||||
Requirement(fallback, result);
|
||||
}
|
||||
|
||||
public object Coalesce(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;
|
||||
}
|
||||
|
||||
return isNull ? flow.GetValue(fallback) : input;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user