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,44 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns true if both inputs are true.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(0)]
public sealed class And : Unit
{
/// <summary>
/// The first boolean.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second boolean.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// True if A and B are both true; false otherwise.
/// </summary>
[DoNotSerialize]
[PortLabel("A & B")]
public ValueOutput result { get; private set; }
protected override void Definition()
{
a = ValueInput<bool>(nameof(a));
b = ValueInput<bool>(nameof(b));
result = ValueOutput(nameof(result), Operation).Predictable();
Requirement(a, result);
Requirement(b, result);
}
public bool Operation(Flow flow)
{
return flow.GetValue<bool>(a) && flow.GetValue<bool>(b);
}
}
}

View file

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

View file

@ -0,0 +1,50 @@
using System;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two numbers to determine if they are approximately equal (disregarding floating point precision errors).
/// </summary>
[UnitCategory("Logic")]
[UnitShortTitle("Equal")]
[UnitSubtitle("(Approximately)")]
[UnitOrder(7)]
[Obsolete("Use the Equal unit with Numeric enabled instead.")]
public sealed class ApproximatelyEqual : Unit
{
/// <summary>
/// The first number.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second number.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// Whether A is approximately equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2248 B")]
public ValueOutput equal { get; private set; }
protected override void Definition()
{
a = ValueInput<float>(nameof(a));
b = ValueInput<float>(nameof(b), 0);
equal = ValueOutput(nameof(equal), Comparison).Predictable();
Requirement(a, equal);
Requirement(b, equal);
}
public bool Comparison(Flow flow)
{
return Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
}
}
}

View file

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

View file

@ -0,0 +1,65 @@
namespace Unity.VisualScripting
{
[UnitCategory("Logic")]
public abstract class BinaryComparisonUnit : Unit
{
/// <summary>
/// The first input.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second input.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
[DoNotSerialize]
public virtual ValueOutput comparison { get; private set; }
/// <summary>
/// Whether the compared inputs are numbers.
/// </summary>
[Serialize]
[Inspectable]
[InspectorToggleLeft]
public bool numeric { get; set; } = true;
// Backwards compatibility
protected virtual string outputKey => nameof(comparison);
protected override void Definition()
{
if (numeric)
{
a = ValueInput<float>(nameof(a));
b = ValueInput<float>(nameof(b), 0);
comparison = ValueOutput(outputKey, NumericComparison).Predictable();
}
else
{
a = ValueInput<object>(nameof(a)).AllowsNull();
b = ValueInput<object>(nameof(b)).AllowsNull();
comparison = ValueOutput(outputKey, GenericComparison).Predictable();
}
Requirement(a, comparison);
Requirement(b, comparison);
}
private bool NumericComparison(Flow flow)
{
return NumericComparison(flow.GetValue<float>(a), flow.GetValue<float>(b));
}
private bool GenericComparison(Flow flow)
{
return GenericComparison(flow.GetValue(a), flow.GetValue(b));
}
protected abstract bool NumericComparison(float a, float b);
protected abstract bool GenericComparison(object a, object b);
}
}

View file

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

View file

@ -0,0 +1,181 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs.
/// </summary>
[UnitCategory("Logic")]
[UnitTitle("Comparison")]
[UnitShortTitle("Comparison")]
[UnitOrder(99)]
public sealed class Comparison : Unit
{
/// <summary>
/// The first input.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second input.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// Whether the compared inputs are numbers.
/// </summary>
[Serialize]
[Inspectable]
public bool numeric { get; set; } = true;
/// <summary>
/// Whether A is less than B.
/// </summary>
[DoNotSerialize]
[PortLabel("A < B")]
public ValueOutput aLessThanB { get; private set; }
/// <summary>
/// Whether A is less than or equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2264 B")]
public ValueOutput aLessThanOrEqualToB { get; private set; }
/// <summary>
/// Whether A is equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A = B")]
public ValueOutput aEqualToB { get; private set; }
/// <summary>
/// Whether A is not equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2260 B")]
public ValueOutput aNotEqualToB { get; private set; }
/// <summary>
/// Whether A is greater than or equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2265 B")]
public ValueOutput aGreaterThanOrEqualToB { get; private set; }
/// <summary>
/// Whether A is greater than B.
/// </summary>
[DoNotSerialize]
[PortLabel("A > B")]
public ValueOutput aGreatherThanB { get; private set; }
protected override void Definition()
{
if (numeric)
{
a = ValueInput<float>(nameof(a));
b = ValueInput<float>(nameof(b), 0);
aLessThanB = ValueOutput(nameof(aLessThanB), (flow) => NumericLess(flow.GetValue<float>(a), flow.GetValue<float>(b))).Predictable();
aLessThanOrEqualToB = ValueOutput(nameof(aLessThanOrEqualToB), (flow) => NumericLessOrEqual(flow.GetValue<float>(a), flow.GetValue<float>(b))).Predictable();
aEqualToB = ValueOutput(nameof(aEqualToB), (flow) => NumericEqual(flow.GetValue<float>(a), flow.GetValue<float>(b))).Predictable();
aNotEqualToB = ValueOutput(nameof(aNotEqualToB), (flow) => NumericNotEqual(flow.GetValue<float>(a), flow.GetValue<float>(b))).Predictable();
aGreaterThanOrEqualToB = ValueOutput(nameof(aGreaterThanOrEqualToB), (flow) => NumericGreaterOrEqual(flow.GetValue<float>(a), flow.GetValue<float>(b))).Predictable();
aGreatherThanB = ValueOutput(nameof(aGreatherThanB), (flow) => NumericGreater(flow.GetValue<float>(a), flow.GetValue<float>(b))).Predictable();
}
else
{
a = ValueInput<object>(nameof(a)).AllowsNull();
b = ValueInput<object>(nameof(b)).AllowsNull();
aLessThanB = ValueOutput(nameof(aLessThanB), (flow) => GenericLess(flow.GetValue(a), flow.GetValue(b)));
aLessThanOrEqualToB = ValueOutput(nameof(aLessThanOrEqualToB), (flow) => GenericLessOrEqual(flow.GetValue(a), flow.GetValue(b)));
aEqualToB = ValueOutput(nameof(aEqualToB), (flow) => GenericEqual(flow.GetValue(a), flow.GetValue(b)));
aNotEqualToB = ValueOutput(nameof(aNotEqualToB), (flow) => GenericNotEqual(flow.GetValue(a), flow.GetValue(b)));
aGreaterThanOrEqualToB = ValueOutput(nameof(aGreaterThanOrEqualToB), (flow) => GenericGreaterOrEqual(flow.GetValue(a), flow.GetValue(b)));
aGreatherThanB = ValueOutput(nameof(aGreatherThanB), (flow) => GenericGreater(flow.GetValue(a), flow.GetValue(b)));
}
Requirement(a, aLessThanB);
Requirement(b, aLessThanB);
Requirement(a, aLessThanOrEqualToB);
Requirement(b, aLessThanOrEqualToB);
Requirement(a, aEqualToB);
Requirement(b, aEqualToB);
Requirement(a, aNotEqualToB);
Requirement(b, aNotEqualToB);
Requirement(a, aGreaterThanOrEqualToB);
Requirement(b, aGreaterThanOrEqualToB);
Requirement(a, aGreatherThanB);
Requirement(b, aGreatherThanB);
}
private bool NumericLess(float a, float b)
{
return a < b;
}
private bool NumericLessOrEqual(float a, float b)
{
return a < b || Mathf.Approximately(a, b);
}
private bool NumericEqual(float a, float b)
{
return Mathf.Approximately(a, b);
}
private bool NumericNotEqual(float a, float b)
{
return !Mathf.Approximately(a, b);
}
private bool NumericGreaterOrEqual(float a, float b)
{
return a > b || Mathf.Approximately(a, b);
}
private bool NumericGreater(float a, float b)
{
return a > b;
}
private bool GenericLess(object a, object b)
{
return OperatorUtility.LessThan(a, b);
}
private bool GenericLessOrEqual(object a, object b)
{
return OperatorUtility.LessThanOrEqual(a, b);
}
private bool GenericEqual(object a, object b)
{
return OperatorUtility.Equal(a, b);
}
private bool GenericNotEqual(object a, object b)
{
return OperatorUtility.NotEqual(a, b);
}
private bool GenericGreaterOrEqual(object a, object b)
{
return OperatorUtility.GreaterThanOrEqual(a, b);
}
private bool GenericGreater(object a, object b)
{
return OperatorUtility.GreaterThan(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,38 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine whether they are equal.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(5)]
public sealed class Equal : BinaryComparisonUnit
{
public Equal() : base()
{
numeric = false;
}
// Backward compatibility
protected override string outputKey => "equal";
/// <summary>
/// Whether A is equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A = B")]
[PortKey("equal")]
public override ValueOutput comparison => base.comparison;
protected override bool NumericComparison(float a, float b)
{
return Mathf.Approximately(a, b);
}
protected override bool GenericComparison(object a, object b)
{
return OperatorUtility.Equal(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,66 @@
using System;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine if they are equal or not equal.
/// </summary>
[UnitCategory("Logic")]
[UnitTitle("Equality Comparison")]
[UnitSurtitle("Equality")]
[UnitShortTitle("Comparison")]
[UnitOrder(4)]
[Obsolete("Use the Comparison unit instead.")]
public sealed class EqualityComparison : Unit
{
/// <summary>
/// The first input.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second input.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// Whether A is equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A = B")]
public ValueOutput equal { get; private set; }
/// <summary>
/// Whether A is different than B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2260 B")]
public ValueOutput notEqual { get; private set; }
protected override void Definition()
{
a = ValueInput<object>(nameof(a)).AllowsNull();
b = ValueInput<object>(nameof(b)).AllowsNull();
equal = ValueOutput(nameof(equal), Equal).Predictable();
notEqual = ValueOutput(nameof(notEqual), NotEqual).Predictable();
Requirement(a, equal);
Requirement(b, equal);
Requirement(a, notEqual);
Requirement(b, notEqual);
}
private bool Equal(Flow flow)
{
return OperatorUtility.Equal(flow.GetValue(a), flow.GetValue(b));
}
private bool NotEqual(Flow flow)
{
return OperatorUtility.NotEqual(flow.GetValue(a), flow.GetValue(b));
}
}
}

View file

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

View file

@ -0,0 +1,44 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns true if one input is true and the other is false.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(2)]
public sealed class ExclusiveOr : Unit
{
/// <summary>
/// The first boolean.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second boolean.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// True if either A or B is true but not the other; false otherwise.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2295 B")]
public ValueOutput result { get; private set; }
protected override void Definition()
{
a = ValueInput<bool>(nameof(a));
b = ValueInput<bool>(nameof(b));
result = ValueOutput(nameof(result), Operation).Predictable();
Requirement(a, result);
Requirement(b, result);
}
public bool Operation(Flow flow)
{
return flow.GetValue<bool>(a) ^ flow.GetValue<bool>(b);
}
}
}

View file

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

View file

@ -0,0 +1,26 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine whether the first is greater than the second.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(11)]
public sealed class Greater : BinaryComparisonUnit
{
/// <summary>
/// Whether A is greater than B.
/// </summary>
[PortLabel("A > B")]
public override ValueOutput comparison => base.comparison;
protected override bool NumericComparison(float a, float b)
{
return a > b;
}
protected override bool GenericComparison(object a, object b)
{
return OperatorUtility.GreaterThan(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,28 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine whether the first is greater than or equal to the second.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(12)]
public sealed class GreaterOrEqual : BinaryComparisonUnit
{
/// <summary>
/// Whether A is greater than or equal to B.
/// </summary>
[PortLabel("A \u2265 B")]
public override ValueOutput comparison => base.comparison;
protected override bool NumericComparison(float a, float b)
{
return a > b || Mathf.Approximately(a, b);
}
protected override bool GenericComparison(object a, object b)
{
return OperatorUtility.GreaterThanOrEqual(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,26 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine whether the first is less than the second.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(9)]
public sealed class Less : BinaryComparisonUnit
{
/// <summary>
/// Whether A is less than B.
/// </summary>
[PortLabel("A < B")]
public override ValueOutput comparison => base.comparison;
protected override bool NumericComparison(float a, float b)
{
return a < b;
}
protected override bool GenericComparison(object a, object b)
{
return OperatorUtility.LessThan(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,28 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine whether the first is less than or equal to the second.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(10)]
public sealed class LessOrEqual : BinaryComparisonUnit
{
/// <summary>
/// Whether A is greater than or equal to B.
/// </summary>
[PortLabel("A \u2264 B")]
public override ValueOutput comparison => base.comparison;
protected override bool NumericComparison(float a, float b)
{
return a < b || Mathf.Approximately(a, b);
}
protected override bool GenericComparison(object a, object b)
{
return OperatorUtility.LessThanOrEqual(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,37 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Inverts the value of a boolean.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(3)]
public sealed class Negate : Unit
{
/// <summary>
/// The input boolean.
/// </summary>
[DoNotSerialize]
[PortLabel("X")]
public ValueInput input { get; private set; }
/// <summary>
/// True if the input is false, false if the input is true.
/// </summary>
[DoNotSerialize]
[PortLabel("~X")]
public ValueOutput output { get; private set; }
protected override void Definition()
{
input = ValueInput<bool>(nameof(input));
output = ValueOutput(nameof(output), Operation).Predictable();
Requirement(input, output);
}
public bool Operation(Flow flow)
{
return !flow.GetValue<bool>(input);
}
}
}

View file

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

View file

@ -0,0 +1,50 @@
using System;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two numbers to determine if they are not approximately equal (disregarding floating point precision errors).
/// </summary>
[UnitCategory("Logic")]
[UnitShortTitle("Not Equal")]
[UnitSubtitle("(Approximately)")]
[UnitOrder(8)]
[Obsolete("Use the Not Equal unit with Numeric enabled instead.")]
public sealed class NotApproximatelyEqual : Unit
{
/// <summary>
/// The first number.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second number.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// Whether A is not approximately equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2249 B")]
public ValueOutput notEqual { get; private set; }
protected override void Definition()
{
a = ValueInput<float>(nameof(a));
b = ValueInput<float>(nameof(b), 0);
notEqual = ValueOutput(nameof(notEqual), Comparison).Predictable();
Requirement(a, notEqual);
Requirement(b, notEqual);
}
public bool Comparison(Flow flow)
{
return !Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
}
}
}

View file

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

View file

@ -0,0 +1,38 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two inputs to determine whether they are not equal.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(6)]
public sealed class NotEqual : BinaryComparisonUnit
{
public NotEqual() : base()
{
numeric = false;
}
// Backward compatibility
protected override string outputKey => "notEqual";
/// <summary>
/// Whether A is different than B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2260 B")]
[PortKey("notEqual")]
public override ValueOutput comparison => base.comparison;
protected override bool NumericComparison(float a, float b)
{
return !Mathf.Approximately(a, b);
}
protected override bool GenericComparison(object a, object b)
{
return OperatorUtility.NotEqual(a, b);
}
}
}

View file

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

View file

@ -0,0 +1,120 @@
using System;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Compares two numeric inputs.
/// </summary>
[UnitCategory("Logic")]
[UnitTitle("Numeric Comparison")]
[UnitSurtitle("Numeric")]
[UnitShortTitle("Comparison")]
[UnitOrder(99)]
[Obsolete("Use the Comparison unit with Numeric enabled instead.")]
public sealed class NumericComparison : Unit
{
/// <summary>
/// The first input.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second input.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// Whether A is less than B.
/// </summary>
[DoNotSerialize]
[PortLabel("A < B")]
public ValueOutput aLessThanB { get; private set; }
/// <summary>
/// Whether A is less than or equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2264 B")]
public ValueOutput aLessThanOrEqualToB { get; private set; }
/// <summary>
/// Whether A is equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A = B")]
public ValueOutput aEqualToB { get; private set; }
/// <summary>
/// Whether A is greater than or equal to B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2265 B")]
public ValueOutput aGreaterThanOrEqualToB { get; private set; }
/// <summary>
/// Whether A is greater than B.
/// </summary>
[DoNotSerialize]
[PortLabel("A > B")]
public ValueOutput aGreatherThanB { get; private set; }
protected override void Definition()
{
a = ValueInput<float>(nameof(a));
b = ValueInput<float>(nameof(b), 0);
aLessThanB = ValueOutput(nameof(aLessThanB), Less).Predictable();
aLessThanOrEqualToB = ValueOutput(nameof(aLessThanOrEqualToB), LessOrEqual).Predictable();
aEqualToB = ValueOutput(nameof(aEqualToB), Equal).Predictable();
aGreaterThanOrEqualToB = ValueOutput(nameof(aGreaterThanOrEqualToB), GreaterOrEqual).Predictable();
aGreatherThanB = ValueOutput(nameof(aGreatherThanB), Greater).Predictable();
Requirement(a, aLessThanB);
Requirement(b, aLessThanB);
Requirement(a, aLessThanOrEqualToB);
Requirement(b, aLessThanOrEqualToB);
Requirement(a, aEqualToB);
Requirement(b, aEqualToB);
Requirement(a, aGreaterThanOrEqualToB);
Requirement(b, aGreaterThanOrEqualToB);
Requirement(a, aGreatherThanB);
Requirement(b, aGreatherThanB);
}
private bool Less(Flow flow)
{
return flow.GetValue<float>(a) < flow.GetValue<float>(b);
}
private bool LessOrEqual(Flow flow)
{
var a = flow.GetValue<float>(this.a);
var b = flow.GetValue<float>(this.b);
return a < b || Mathf.Approximately(a, b);
}
private bool Equal(Flow flow)
{
return Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
}
private bool GreaterOrEqual(Flow flow)
{
var a = flow.GetValue<float>(this.a);
var b = flow.GetValue<float>(this.b);
return a > b || Mathf.Approximately(a, b);
}
private bool Greater(Flow flow)
{
return flow.GetValue<float>(a) < flow.GetValue<float>(b);
}
}
}

View file

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

View file

@ -0,0 +1,44 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns true if either input is true.
/// </summary>
[UnitCategory("Logic")]
[UnitOrder(1)]
public sealed class Or : Unit
{
/// <summary>
/// The first boolean.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second boolean.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// True if either A or B is true; false otherwise.
/// </summary>
[DoNotSerialize]
[PortLabel("A | B")]
public ValueOutput result { get; private set; }
protected override void Definition()
{
a = ValueInput<bool>(nameof(a));
b = ValueInput<bool>(nameof(b));
result = ValueOutput(nameof(result), Operation).Predictable();
Requirement(a, result);
Requirement(b, result);
}
public bool Operation(Flow flow)
{
return flow.GetValue<bool>(a) || flow.GetValue<bool>(b);
}
}
}

View file

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