Initial Commit

This commit is contained in:
Sebastian Cabrera 2021-08-02 05:44:37 -04:00
parent 53eb92e9af
commit 270ab7d11f
15341 changed files with 700234 additions and 0 deletions

View file

@ -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();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8ec22038ca8d40ac94e3ff3762cb5b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 43602ed57f2144e3aac6c16edf4cac3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fafc0ba4e24ff411697e06cb5daf09b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: