This commit is contained in:
2021-06-13 10:28:03 +02:00
parent eb70603c85
commit df2d24cbd3
7487 changed files with 943244 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
namespace Unity.VisualScripting
{
[UnitOrder(201)]
public abstract class Absolute<TInput> : Unit
{
/// <summary>
/// The value to make positive.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueInput input { get; private set; }
/// <summary>
/// The positive value.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput output { get; private set; }
protected override void Definition()
{
input = ValueInput<TInput>(nameof(input));
output = ValueOutput(nameof(output), Operation).Predictable();
Requirement(input, output);
}
protected abstract TInput Operation(TInput input);
public TInput Operation(Flow flow)
{
return Operation(flow.GetValue<TInput>(input));
}
}
}

View File

@@ -0,0 +1,46 @@
namespace Unity.VisualScripting
{
[UnitOrder(101)]
public abstract class Add<T> : Unit
{
/// <summary>
/// The first value.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second value.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The sum of A and B.
/// </summary>
[DoNotSerialize]
[PortLabel("A + B")]
public ValueOutput sum { get; private set; }
[DoNotSerialize]
protected virtual T defaultB => default(T);
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput(nameof(b), defaultB);
sum = ValueOutput(nameof(sum), Operation).Predictable();
Requirement(a, sum);
Requirement(b, sum);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract T Operation(T a, T b);
}
}

View File

@@ -0,0 +1,42 @@
namespace Unity.VisualScripting
{
[UnitOrder(403)]
public abstract class Angle<T> : Unit
{
/// <summary>
/// The first vector.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second vector.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The angle between A and B.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput angle { get; private set; }
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput<T>(nameof(b));
angle = ValueOutput(nameof(angle), Operation).Predictable();
Requirement(a, angle);
Requirement(b, angle);
}
private float Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract float Operation(T a, T b);
}
}

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
[UnitOrder(304)]
public abstract class Average<T> : MultiInputUnit<T>
{
/// <summary>
/// The average.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput average { get; private set; }
protected override void Definition()
{
base.Definition();
average = ValueOutput(nameof(average), Operation).Predictable();
foreach (var multiInput in multiInputs)
{
Requirement(multiInput, average);
}
}
public abstract T Operation(T a, T b);
public abstract T Operation(IEnumerable<T> values);
public T Operation(Flow flow)
{
if (inputCount == 2)
{
return Operation(flow.GetValue<T>(multiInputs[0]), flow.GetValue<T>(multiInputs[1]));
}
else
{
return Operation(multiInputs.Select(flow.GetValue<T>));
}
}
}
}

View File

@@ -0,0 +1,43 @@
namespace Unity.VisualScripting
{
[UnitOrder(405)]
[TypeIcon(typeof(Multiply<>))]
public abstract class CrossProduct<T> : Unit
{
/// <summary>
/// The first vector.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second vector.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The cross product of A and B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u00D7 B")]
public ValueOutput crossProduct { get; private set; }
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput<T>(nameof(b));
crossProduct = ValueOutput(nameof(crossProduct), Operation).Predictable();
Requirement(a, crossProduct);
Requirement(b, crossProduct);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract T Operation(T a, T b);
}
}

View File

@@ -0,0 +1,42 @@
namespace Unity.VisualScripting
{
[UnitOrder(402)]
public abstract class Distance<T> : Unit
{
/// <summary>
/// The first vector.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second vector.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The distance between A and B.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput distance { get; private set; }
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput<T>(nameof(b));
distance = ValueOutput(nameof(distance), Operation).Predictable();
Requirement(a, distance);
Requirement(b, distance);
}
private float Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract float Operation(T a, T b);
}
}

View File

@@ -0,0 +1,50 @@
namespace Unity.VisualScripting
{
[UnitOrder(104)]
public abstract class Divide<T> : Unit
{
/// <summary>
/// The dividend (or numerator).
/// </summary>
[DoNotSerialize]
[PortLabel("A")]
public ValueInput dividend { get; private set; }
/// <summary>
/// The divisor (or denominator).
/// </summary>
[DoNotSerialize]
[PortLabel("B")]
public ValueInput divisor { get; private set; }
/// <summary>
/// The quotient of the dividend and divisor (numerator / denominator).
/// </summary>
[DoNotSerialize]
[PortLabel("A \u00F7 B")]
public ValueOutput quotient { get; private set; }
[DoNotSerialize]
protected virtual T defaultDivisor => default(T);
[DoNotSerialize]
protected virtual T defaultDividend => default(T);
protected override void Definition()
{
dividend = ValueInput(nameof(dividend), defaultDividend);
divisor = ValueInput(nameof(divisor), defaultDivisor);
quotient = ValueOutput(nameof(quotient), Operation).Predictable();
Requirement(dividend, quotient);
Requirement(divisor, quotient);
}
public abstract T Operation(T divident, T divisor);
public T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(dividend), flow.GetValue<T>(divisor));
}
}
}

View File

@@ -0,0 +1,42 @@
namespace Unity.VisualScripting
{
[UnitOrder(404)]
public abstract class DotProduct<T> : Unit
{
/// <summary>
/// The first vector.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second vector.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The dot product of A and B.
/// </summary>
[DoNotSerialize]
[PortLabel("A\u2219B")]
public ValueOutput dotProduct { get; private set; }
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput<T>(nameof(b));
dotProduct = ValueOutput(nameof(dotProduct), Operation).Predictable();
Requirement(a, dotProduct);
Requirement(b, dotProduct);
}
private float Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract float Operation(T a, T b);
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two objects.
/// </summary>
[UnitCategory("Math/Generic")]
[UnitTitle("Add")]
[RenamedFrom("Bolt.GenericAdd")]
[RenamedFrom("Unity.VisualScripting.GenericAdd")]
[Obsolete("Use the new \"Add (Math/Generic)\" unit instead.")]
public sealed class DeprecatedGenericAdd : Add<object>
{
public override object Operation(object a, object b)
{
return OperatorUtility.Add(a, b);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the quotient of two objects.
/// </summary>
[UnitCategory("Math/Generic")]
[UnitTitle("Divide")]
public sealed class GenericDivide : Divide<object>
{
public override object Operation(object a, object b)
{
return OperatorUtility.Divide(a, b);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the remainder of the division of two objects.
/// </summary>
[UnitCategory("Math/Generic")]
[UnitTitle("Modulo")]
public sealed class GenericModulo : Modulo<object>
{
public override object Operation(object a, object b)
{
return OperatorUtility.Modulo(a, b);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the product of two objects.
/// </summary>
[UnitCategory("Math/Generic")]
[UnitTitle("Multiply")]
public sealed class GenericMultiply : Multiply<object>
{
public override object Operation(object a, object b)
{
return OperatorUtility.Multiply(a, b);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the difference between two objects.
/// </summary>
[UnitCategory("Math/Generic")]
[UnitTitle("Subtract")]
public sealed class GenericSubtract : Subtract<object>
{
public override object Operation(object a, object b)
{
return OperatorUtility.Subtract(a, b);
}
}
}

View File

@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two objects.
/// </summary>
[UnitCategory("Math/Generic")]
[UnitTitle("Add")]
public sealed class GenericSum : Sum<object>
{
public override object Operation(object a, object b)
{
return OperatorUtility.Add(a, b);
}
public override object Operation(IEnumerable<object> values)
{
var valueList = values.ToList();
var result = OperatorUtility.Add(valueList[0], valueList[1]);
for (int i = 2; i < valueList.Count; i++)
{
result = OperatorUtility.Add(result, valueList[i]);
}
return result;
}
}
}

View File

@@ -0,0 +1,56 @@
namespace Unity.VisualScripting
{
[UnitOrder(501)]
public abstract class Lerp<T> : Unit
{
/// <summary>
/// The first value.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second value.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The interpolation value.
/// </summary>
[DoNotSerialize]
public ValueInput t { get; private set; }
/// <summary>
/// The linear interpolation between A and B at T.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput interpolation { get; private set; }
[DoNotSerialize]
protected virtual T defaultA => default(T);
[DoNotSerialize]
protected virtual T defaultB => default(T);
protected override void Definition()
{
a = ValueInput(nameof(a), defaultA);
b = ValueInput(nameof(b), defaultB);
t = ValueInput<float>(nameof(t), 0);
interpolation = ValueOutput(nameof(interpolation), Operation).Predictable();
Requirement(a, interpolation);
Requirement(b, interpolation);
Requirement(t, interpolation);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b), flow.GetValue<float>(t));
}
public abstract T Operation(T a, T b, float t);
}
}

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
[UnitOrder(302)]
public abstract class Maximum<T> : MultiInputUnit<T>
{
/// <summary>
/// The maximum.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput maximum { get; private set; }
protected override void Definition()
{
base.Definition();
maximum = ValueOutput(nameof(maximum), Operation).Predictable();
foreach (var multiInput in multiInputs)
{
Requirement(multiInput, maximum);
}
}
public abstract T Operation(T a, T b);
public abstract T Operation(IEnumerable<T> values);
public T Operation(Flow flow)
{
if (inputCount == 2)
{
return Operation(flow.GetValue<T>(multiInputs[0]), flow.GetValue<T>(multiInputs[1]));
}
else
{
return Operation(multiInputs.Select(flow.GetValue<T>));
}
}
}
}

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
[UnitOrder(301)]
public abstract class Minimum<T> : MultiInputUnit<T>
{
/// <summary>
/// The minimum.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput minimum { get; private set; }
protected override void Definition()
{
base.Definition();
minimum = ValueOutput(nameof(minimum), Operation).Predictable();
foreach (var multiInput in multiInputs)
{
Requirement(multiInput, minimum);
}
}
public abstract T Operation(T a, T b);
public abstract T Operation(IEnumerable<T> values);
public T Operation(Flow flow)
{
if (inputCount == 2)
{
return Operation(flow.GetValue<T>(multiInputs[0]), flow.GetValue<T>(multiInputs[1]));
}
else
{
return Operation(multiInputs.Select(flow.GetValue<T>));
}
}
}
}

View File

@@ -0,0 +1,50 @@
namespace Unity.VisualScripting
{
[UnitOrder(105)]
public abstract class Modulo<T> : Unit
{
/// <summary>
/// The dividend (or numerator).
/// </summary>
[DoNotSerialize]
[PortLabel("A")]
public ValueInput dividend { get; private set; }
/// <summary>
/// The divisor (or denominator).
/// </summary>
[DoNotSerialize]
[PortLabel("B")]
public ValueInput divisor { get; private set; }
/// <summary>
/// The remainder of the division of dividend and divison (numerator / denominator).
/// </summary>
[DoNotSerialize]
[PortLabel("A % B")]
public ValueOutput remainder { get; private set; }
[DoNotSerialize]
protected virtual T defaultDivisor => default(T);
[DoNotSerialize]
protected virtual T defaultDividend => default(T);
protected override void Definition()
{
dividend = ValueInput(nameof(dividend), defaultDividend);
divisor = ValueInput(nameof(divisor), defaultDivisor);
remainder = ValueOutput(nameof(remainder), Operation).Predictable();
Requirement(dividend, remainder);
Requirement(divisor, remainder);
}
public abstract T Operation(T divident, T divisor);
public T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(dividend), flow.GetValue<T>(divisor));
}
}
}

View File

@@ -0,0 +1,61 @@
using UnityEngine;
namespace Unity.VisualScripting
{
[UnitOrder(502)]
public abstract class MoveTowards<T> : Unit
{
/// <summary>
/// The current value.
/// </summary>
[DoNotSerialize]
public ValueInput current { get; private set; }
/// <summary>
/// The target value.
/// </summary>
[DoNotSerialize]
public ValueInput target { get; private set; }
/// <summary>
/// The maximum scalar increment between values.
/// </summary>
[DoNotSerialize]
public ValueInput maxDelta { get; private set; }
/// <summary>
/// The incremented value.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput result { get; private set; }
[Serialize, Inspectable, UnitHeaderInspectable("Per Second"), InspectorToggleLeft]
public bool perSecond { get; set; }
[DoNotSerialize]
protected virtual T defaultCurrent => default(T);
[DoNotSerialize]
protected virtual T defaultTarget => default(T);
protected override void Definition()
{
current = ValueInput(nameof(current), defaultCurrent);
target = ValueInput(nameof(target), defaultTarget);
maxDelta = ValueInput<float>(nameof(maxDelta), 0);
result = ValueOutput(nameof(result), Operation);
Requirement(current, result);
Requirement(target, result);
Requirement(maxDelta, result);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(current), flow.GetValue<T>(target), flow.GetValue<float>(maxDelta) * (perSecond ? Time.deltaTime : 1));
}
public abstract T Operation(T current, T target, float maxDelta);
}
}

View File

@@ -0,0 +1,45 @@
namespace Unity.VisualScripting
{
[UnitOrder(103)]
public abstract class Multiply<T> : Unit
{
/// <summary>
/// The first value.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The second value.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The product of A and B.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u00D7 B")]
public ValueOutput product { get; private set; }
[DoNotSerialize]
protected virtual T defaultB => default(T);
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput(nameof(b), defaultB);
product = ValueOutput(nameof(product), Operation).Predictable();
Requirement(a, product);
Requirement(b, product);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract T Operation(T a, T b);
}
}

View File

@@ -0,0 +1,35 @@
namespace Unity.VisualScripting
{
[UnitOrder(401)]
public abstract class Normalize<T> : Unit
{
/// <summary>
/// The vector to normalize.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueInput input { get; private set; }
/// <summary>
/// The normalized vector.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput output { get; private set; }
protected override void Definition()
{
input = ValueInput<T>(nameof(input));
output = ValueOutput(nameof(output), Operation).Predictable();
Requirement(input, output);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(input));
}
public abstract T Operation(T input);
}
}

View File

@@ -0,0 +1,35 @@
namespace Unity.VisualScripting
{
[UnitOrder(601)]
public abstract class PerSecond<T> : Unit
{
/// <summary>
/// The input value.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueInput input { get; private set; }
/// <summary>
/// The framerate-normalized value (multiplied by delta time).
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput output { get; private set; }
protected override void Definition()
{
input = ValueInput(nameof(input), default(T));
output = ValueOutput(nameof(output), Operation);
Requirement(input, output);
}
public abstract T Operation(T input);
public T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(input));
}
}
}

View File

@@ -0,0 +1,42 @@
namespace Unity.VisualScripting
{
[UnitOrder(406)]
public abstract class Project<T> : Unit
{
/// <summary>
/// The vector to project.
/// </summary>
[DoNotSerialize]
public ValueInput a { get; private set; }
/// <summary>
/// The vector on which to project.
/// </summary>
[DoNotSerialize]
public ValueInput b { get; private set; }
/// <summary>
/// The projection of A on B.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput projection { get; private set; }
protected override void Definition()
{
a = ValueInput<T>(nameof(a));
b = ValueInput<T>(nameof(b));
projection = ValueOutput(nameof(projection), Operation).Predictable();
Requirement(a, projection);
Requirement(b, projection);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
}
public abstract T Operation(T a, T b);
}
}

View File

@@ -0,0 +1,60 @@
namespace Unity.VisualScripting
{
[UnitOrder(202)]
public abstract class Round<TInput, TOutput> : Unit
{
public enum Rounding
{
Floor = 0,
Ceiling = 1,
AwayFromZero = 2,
}
/// <summary>
/// The rounding mode.
/// </summary>
[Inspectable, UnitHeaderInspectable, Serialize]
public Rounding rounding { get; set; } = Rounding.AwayFromZero;
/// <summary>
/// The value to round.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueInput input { get; private set; }
/// <summary>
/// The rounded value.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput output { get; private set; }
protected override void Definition()
{
input = ValueInput<TInput>(nameof(input));
output = ValueOutput(nameof(output), Operation).Predictable();
Requirement(input, output);
}
protected abstract TOutput Floor(TInput input);
protected abstract TOutput AwayFromZero(TInput input);
protected abstract TOutput Ceiling(TInput input);
public TOutput Operation(Flow flow)
{
switch (rounding)
{
case Rounding.Floor:
return Floor(flow.GetValue<TInput>(input));
case Rounding.AwayFromZero:
return AwayFromZero(flow.GetValue<TInput>(input));
case Rounding.Ceiling:
return Ceiling(flow.GetValue<TInput>(input));
default:
throw new UnexpectedEnumValueException<Rounding>(rounding);
}
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Add")]
[Obsolete("Use the new \"Add (Math/Scalar)\" unit instead.")]
[RenamedFrom("Bolt.ScalarAdd")]
[RenamedFrom("Unity.VisualScripting.ScalarAdd")]
public sealed class DeprecatedScalarAdd : Add<float>
{
protected override float defaultB => 1;
public override float Operation(float a, float b)
{
return a + b;
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the positive version of a scalar.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Absolute")]
public sealed class ScalarAbsolute : Absolute<float>
{
protected override float Operation(float input)
{
return Mathf.Abs(input);
}
}
}

View File

@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the average of two or more scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Average")]
public sealed class ScalarAverage : Average<float>
{
public override float Operation(float a, float b)
{
return (a + b) / 2;
}
public override float Operation(IEnumerable<float> values)
{
return values.Average();
}
}
}

View File

@@ -0,0 +1,19 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the quotient of two scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Divide")]
public sealed class ScalarDivide : Divide<float>
{
protected override float defaultDividend => 1;
protected override float defaultDivisor => 1;
public override float Operation(float a, float b)
{
return a / b;
}
}
}

View File

@@ -0,0 +1,49 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the power of a base and exponent.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Exponentiate")]
[UnitOrder(105)]
public sealed class ScalarExponentiate : Unit
{
/// <summary>
/// The base.
/// </summary>
[DoNotSerialize]
[PortLabel("x")]
public ValueInput @base { get; private set; }
/// <summary>
/// The exponent.
/// </summary>
[DoNotSerialize]
[PortLabel("n")]
public ValueInput exponent { get; private set; }
/// <summary>
/// The power of base elevated to exponent.
/// </summary>
[DoNotSerialize]
[PortLabel("x\u207f")]
public ValueOutput power { get; private set; }
protected override void Definition()
{
@base = ValueInput<float>(nameof(@base), 1);
exponent = ValueInput<float>(nameof(exponent), 2);
power = ValueOutput(nameof(power), Exponentiate);
Requirement(@base, power);
Requirement(exponent, power);
}
public float Exponentiate(Flow flow)
{
return Mathf.Pow(flow.GetValue<float>(@base), flow.GetValue<float>(exponent));
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the linear interpolation between two scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Lerp")]
public sealed class ScalarLerp : Lerp<float>
{
protected override float defaultA => 0;
protected override float defaultB => 1;
public override float Operation(float a, float b, float t)
{
return Mathf.Lerp(a, b, t);
}
}
}

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the maximum between two or more scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Maximum")]
public sealed class ScalarMaximum : Maximum<float>
{
public override float Operation(float a, float b)
{
return Mathf.Max(a, b);
}
public override float Operation(IEnumerable<float> values)
{
return values.Max();
}
}
}

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the minimum between two or more scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Minimum")]
public sealed class ScalarMinimum : Minimum<float>
{
public override float Operation(float a, float b)
{
return Mathf.Min(a, b);
}
public override float Operation(IEnumerable<float> values)
{
return values.Min();
}
}
}

View File

@@ -0,0 +1,19 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the remainder of the division of two scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Modulo")]
public sealed class ScalarModulo : Modulo<float>
{
protected override float defaultDividend => 1;
protected override float defaultDivisor => 1;
public override float Operation(float a, float b)
{
return a % b;
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Moves a scalar towards a target.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Move Towards")]
public sealed class ScalarMoveTowards : MoveTowards<float>
{
protected override float defaultCurrent => 0;
protected override float defaultTarget => 1;
public override float Operation(float current, float target, float maxDelta)
{
return Mathf.MoveTowards(current, target, maxDelta);
}
}
}

View File

@@ -0,0 +1,17 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the product of two scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Multiply")]
public sealed class ScalarMultiply : Multiply<float>
{
protected override float defaultB => 1;
public override float Operation(float a, float b)
{
return a * b;
}
}
}

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the unit length version of a scalar.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Normalize")]
public sealed class ScalarNormalize : Normalize<float>
{
public override float Operation(float input)
{
if (input == 0)
{
return 0;
}
return input / Mathf.Abs(input);
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the framerate-normalized value of a scalar.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Per Second")]
public sealed class ScalarPerSecond : PerSecond<float>
{
public override float Operation(float input)
{
return input * Time.deltaTime;
}
}
}

View File

@@ -0,0 +1,59 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the root at the nth degree of a radicand.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Root")]
[UnitOrder(106)]
public sealed class ScalarRoot : Unit
{
/// <summary>
/// The radicand.
/// </summary>
[DoNotSerialize]
[PortLabel("x")]
public ValueInput radicand { get; private set; }
/// <summary>
/// The degree.
/// </summary>
[DoNotSerialize]
[PortLabel("n")]
public ValueInput degree { get; private set; }
/// <summary>
/// The nth degree root of the radicand.
/// </summary>
[DoNotSerialize]
[PortLabel("\u207f\u221ax")]
public ValueOutput root { get; private set; }
protected override void Definition()
{
radicand = ValueInput<float>(nameof(radicand), 1);
degree = ValueInput<float>(nameof(degree), 2);
root = ValueOutput(nameof(root), Root);
Requirement(radicand, root);
Requirement(degree, root);
}
public float Root(Flow flow)
{
var degree = flow.GetValue<float>(this.degree);
var radicand = flow.GetValue<float>(this.radicand);
if (degree == 2)
{
return Mathf.Sqrt(radicand);
}
else
{
return Mathf.Pow(radicand, 1 / degree);
}
}
}
}

View File

@@ -0,0 +1,27 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Rounds a decimal number to return an integer.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Round")]
public sealed class ScalarRound : Round<float, int>
{
protected override int Floor(float input)
{
return Mathf.FloorToInt(input);
}
protected override int AwayFromZero(float input)
{
return Mathf.RoundToInt(input);
}
protected override int Ceiling(float input)
{
return Mathf.CeilToInt(input);
}
}
}

View File

@@ -0,0 +1,19 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the difference between two scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Subtract")]
public sealed class ScalarSubtract : Subtract<float>
{
protected override float defaultMinuend => 1;
protected override float defaultSubtrahend => 1;
public override float Operation(float a, float b)
{
return a - b;
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two or more scalars.
/// </summary>
[UnitCategory("Math/Scalar")]
[UnitTitle("Add")]
public sealed class ScalarSum : Sum<float>, IDefaultValue<float>
{
[DoNotSerialize]
public float defaultValue => 1;
public override float Operation(float a, float b)
{
return a + b;
}
public override float Operation(IEnumerable<float> values)
{
return values.Sum();
}
}
}

View File

@@ -0,0 +1,50 @@
namespace Unity.VisualScripting
{
[UnitOrder(102)]
public abstract class Subtract<T> : Unit
{
/// <summary>
/// The first value (minuend).
/// </summary>
[DoNotSerialize]
[PortLabel("A")]
public ValueInput minuend { get; private set; }
/// <summary>
/// The second value (subtrahend).
/// </summary>
[DoNotSerialize]
[PortLabel("B")]
public ValueInput subtrahend { get; private set; }
/// <summary>
/// The difference, that is the minuend minus the subtrahend.
/// </summary>
[DoNotSerialize]
[PortLabel("A \u2212 B")]
public ValueOutput difference { get; private set; }
[DoNotSerialize]
protected virtual T defaultMinuend => default(T);
[DoNotSerialize]
protected virtual T defaultSubtrahend => default(T);
protected override void Definition()
{
minuend = ValueInput(nameof(minuend), defaultMinuend);
subtrahend = ValueInput(nameof(subtrahend), defaultSubtrahend);
difference = ValueOutput(nameof(difference), Operation).Predictable();
Requirement(minuend, difference);
Requirement(subtrahend, difference);
}
public abstract T Operation(T a, T b);
public T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(minuend), flow.GetValue<T>(subtrahend));
}
}
}

View File

@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
[UnitOrder(303)]
[TypeIcon(typeof(Add<>))]
public abstract class Sum<T> : MultiInputUnit<T>
{
/// <summary>
/// The sum.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput sum { get; private set; }
protected override void Definition()
{
if (this is IDefaultValue<T> defaultValueUnit)
{
var mi = new List<ValueInput>();
multiInputs = mi.AsReadOnly();
for (var i = 0; i < inputCount; i++)
{
if (i == 0)
{
mi.Add(ValueInput<T>(i.ToString()));
continue;
}
mi.Add(ValueInput(i.ToString(), defaultValueUnit.defaultValue));
}
}
else
{
base.Definition();
}
sum = ValueOutput(nameof(sum), Operation).Predictable();
foreach (var multiInput in multiInputs)
{
Requirement(multiInput, sum);
}
}
public abstract T Operation(T a, T b);
public abstract T Operation(IEnumerable<T> values);
public T Operation(Flow flow)
{
if (inputCount == 2)
{
return Operation(flow.GetValue<T>(multiInputs[0]), flow.GetValue<T>(multiInputs[1]));
}
else
{
return Operation(multiInputs.Select(flow.GetValue<T>));
}
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Add")]
[Obsolete("Use the new \"Add (Math/Vector 2)\" unit instead.")]
[RenamedFrom("Bolt.Vector2Add")]
[RenamedFrom("Unity.VisualScripting.Vector2Add")]
public sealed class DeprecatedVector2Add : Add<Vector2>
{
protected override Vector2 defaultB => Vector2.zero;
public override Vector2 Operation(Vector2 a, Vector2 b)
{
return a + b;
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns a version of a 2D vector where each component is positive.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Absolute")]
public sealed class Vector2Absolute : Absolute<Vector2>
{
protected override Vector2 Operation(Vector2 input)
{
return new Vector2(Mathf.Abs(input.x), Mathf.Abs(input.y));
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the angle between two 2D vectors in degrees.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Angle")]
public sealed class Vector2Angle : Angle<UnityEngine.Vector2>
{
public override float Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return UnityEngine.Vector2.Angle(a, b);
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the average of two or more 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Average")]
public sealed class Vector2Average : Average<UnityEngine.Vector2>
{
public override UnityEngine.Vector2 Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return (a + b) / 2;
}
public override UnityEngine.Vector2 Operation(IEnumerable<UnityEngine.Vector2> values)
{
var average = UnityEngine.Vector2.zero;
var count = 0;
foreach (var value in values)
{
average += value;
count++;
}
average /= count;
return average;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the distance between two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Distance")]
public sealed class Vector2Distance : Distance<UnityEngine.Vector2>
{
public override float Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return UnityEngine.Vector2.Distance(a, b);
}
}
}

View File

@@ -0,0 +1,25 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise quotient of two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Divide")]
public sealed class Vector2Divide : Divide<Vector2>
{
protected override Vector2 defaultDividend => Vector2.zero;
protected override Vector2 defaultDivisor => Vector2.zero;
public override Vector2 Operation(Vector2 a, Vector2 b)
{
return new Vector2
(
a.x / b.x,
a.y / b.y
);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the dot product of two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Dot Product")]
public sealed class Vector2DotProduct : DotProduct<UnityEngine.Vector2>
{
public override float Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return UnityEngine.Vector2.Dot(a, b);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the linear interpolation between two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Lerp")]
public sealed class Vector2Lerp : Lerp<Vector2>
{
protected override Vector2 defaultA => Vector2.zero;
protected override Vector2 defaultB => Vector2.one;
public override Vector2 Operation(Vector2 a, Vector2 b, float t)
{
return Vector2.Lerp(a, b, t);
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise maximum between two or more 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Maximum")]
public sealed class Vector2Maximum : Maximum<UnityEngine.Vector2>
{
public override UnityEngine.Vector2 Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return UnityEngine.Vector2.Max(a, b);
}
public override UnityEngine.Vector2 Operation(IEnumerable<UnityEngine.Vector2> values)
{
var defined = false;
var maximum = UnityEngine.Vector2.zero;
foreach (var value in values)
{
if (!defined)
{
maximum = value;
defined = true;
}
else
{
maximum = UnityEngine.Vector2.Max(maximum, value);
}
}
return maximum;
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise minimum between two or more 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Minimum")]
public sealed class Vector2Minimum : Minimum<UnityEngine.Vector2>
{
public override UnityEngine.Vector2 Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return UnityEngine.Vector2.Min(a, b);
}
public override UnityEngine.Vector2 Operation(IEnumerable<UnityEngine.Vector2> values)
{
var defined = false;
var minimum = UnityEngine.Vector2.zero;
foreach (var value in values)
{
if (!defined)
{
minimum = value;
defined = true;
}
else
{
minimum = UnityEngine.Vector2.Min(minimum, value);
}
}
return minimum;
}
}
}

View File

@@ -0,0 +1,25 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the remainder of the component-wise division of two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Modulo")]
public sealed class Vector2Modulo : Modulo<Vector2>
{
protected override Vector2 defaultDividend => Vector2.zero;
protected override Vector2 defaultDivisor => Vector2.zero;
public override Vector2 Operation(Vector2 a, Vector2 b)
{
return new Vector2
(
a.x % b.x,
a.y % b.y
);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Moves a 2D vector towards a target.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Move Towards")]
public sealed class Vector2MoveTowards : MoveTowards<Vector2>
{
protected override Vector2 defaultCurrent => Vector2.zero;
protected override Vector2 defaultTarget => Vector2.one;
public override Vector2 Operation(Vector2 current, Vector2 target, float maxDelta)
{
return Vector2.MoveTowards(current, target, maxDelta);
}
}
}

View File

@@ -0,0 +1,23 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise product of two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Multiply")]
public sealed class Vector2Multiply : Multiply<Vector2>
{
protected override Vector2 defaultB => Vector2.zero;
public override Vector2 Operation(Vector2 a, Vector2 b)
{
return new Vector2
(
a.x * b.x,
a.y * b.y
);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the unit length version of a 2D vector.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Normalize")]
public sealed class Vector2Normalize : Normalize<UnityEngine.Vector2>
{
public override UnityEngine.Vector2 Operation(UnityEngine.Vector2 input)
{
return input.normalized;
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the framerate-normalized value of a 2D vector.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Per Second")]
public sealed class Vector2PerSecond : PerSecond<Vector2>
{
public override Vector2 Operation(Vector2 input)
{
return input * Time.deltaTime;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the projection of a 2D vector on another.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Project")]
public sealed class Vector2Project : Project<UnityEngine.Vector2>
{
public override UnityEngine.Vector2 Operation(UnityEngine.Vector2 a, UnityEngine.Vector2 b)
{
return UnityEngine.Vector2.Dot(a, b) * b.normalized;
}
}
}

View File

@@ -0,0 +1,39 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Rounds each component of a 2D vector.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Round")]
public sealed class Vector2Round : Round<Vector2, Vector2>
{
protected override Vector2 Floor(Vector2 input)
{
return new Vector2
(
Mathf.Floor(input.x),
Mathf.Floor(input.y)
);
}
protected override Vector2 AwayFromZero(Vector2 input)
{
return new Vector2
(
Mathf.Round(input.x),
Mathf.Round(input.y)
);
}
protected override Vector2 Ceiling(Vector2 input)
{
return new Vector2
(
Mathf.Ceil(input.x),
Mathf.Ceil(input.y)
);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the difference between two 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Subtract")]
public sealed class Vector2Subtract : Subtract<Vector2>
{
protected override Vector2 defaultMinuend => Vector2.zero;
protected override Vector2 defaultSubtrahend => Vector2.zero;
public override Vector2 Operation(Vector2 a, Vector2 b)
{
return a - b;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two or more 2D vectors.
/// </summary>
[UnitCategory("Math/Vector 2")]
[UnitTitle("Add")]
public sealed class Vector2Sum : Sum<Vector2>, IDefaultValue<Vector2>
{
[DoNotSerialize]
public Vector2 defaultValue => Vector2.zero;
public override Vector2 Operation(Vector2 a, Vector2 b)
{
return a + b;
}
public override Vector2 Operation(IEnumerable<Vector2> values)
{
var sum = Vector2.zero;
foreach (var value in values)
{
sum += value;
}
return sum;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Add")]
[Obsolete("Use the new \"Add (Math/Vector 3)\" instead.")]
[RenamedFrom("Bolt.Vector3Add")]
[RenamedFrom("Unity.VisualScripting.Vector3Add")]
public sealed class DeprecatedVector3Add : Add<Vector3>
{
protected override Vector3 defaultB => Vector3.zero;
public override Vector3 Operation(Vector3 a, Vector3 b)
{
return a + b;
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns a version of a 3D vector where each component is positive.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Absolute")]
public sealed class Vector3Absolute : Absolute<Vector3>
{
protected override Vector3 Operation(Vector3 input)
{
return new Vector3(Mathf.Abs(input.x), Mathf.Abs(input.y), Mathf.Abs(input.z));
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the angle between two 3D vectors in degrees.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Angle")]
public sealed class Vector3Angle : Angle<UnityEngine.Vector3>
{
public override float Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Angle(a, b);
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the average of two or more 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Average")]
public sealed class Vector3Average : Average<UnityEngine.Vector3>
{
public override UnityEngine.Vector3 Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return (a + b) / 2;
}
public override UnityEngine.Vector3 Operation(IEnumerable<UnityEngine.Vector3> values)
{
var average = UnityEngine.Vector3.zero;
var count = 0;
foreach (var value in values)
{
average += value;
count++;
}
average /= count;
return average;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the cross product of two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Cross Product")]
public sealed class Vector3CrossProduct : CrossProduct<UnityEngine.Vector3>
{
public override UnityEngine.Vector3 Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Cross(a, b);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the distance between two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Distance")]
public sealed class Vector3Distance : Distance<UnityEngine.Vector3>
{
public override float Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Distance(a, b);
}
}
}

View File

@@ -0,0 +1,26 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise quotient of two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Divide")]
public sealed class Vector3Divide : Divide<Vector3>
{
protected override Vector3 defaultDividend => Vector3.zero;
protected override Vector3 defaultDivisor => Vector3.zero;
public override Vector3 Operation(Vector3 a, Vector3 b)
{
return new Vector3
(
a.x / b.x,
a.y / b.y,
a.z / b.z
);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the dot product of two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Dot Product")]
public sealed class Vector3DotProduct : DotProduct<UnityEngine.Vector3>
{
public override float Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Dot(a, b);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the linear interpolation between two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Lerp")]
public sealed class Vector3Lerp : Lerp<Vector3>
{
protected override Vector3 defaultA => Vector3.zero;
protected override Vector3 defaultB => Vector3.one;
public override Vector3 Operation(Vector3 a, Vector3 b, float t)
{
return Vector3.Lerp(a, b, t);
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise maximum between two or more 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Maximum")]
public sealed class Vector3Maximum : Maximum<UnityEngine.Vector3>
{
public override UnityEngine.Vector3 Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Max(a, b);
}
public override UnityEngine.Vector3 Operation(IEnumerable<UnityEngine.Vector3> values)
{
var defined = false;
var maximum = UnityEngine.Vector3.zero;
foreach (var value in values)
{
if (!defined)
{
maximum = value;
defined = true;
}
else
{
maximum = UnityEngine.Vector3.Max(maximum, value);
}
}
return maximum;
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise minimum between two or more 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Minimum")]
public sealed class Vector3Minimum : Minimum<UnityEngine.Vector3>
{
public override UnityEngine.Vector3 Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Min(a, b);
}
public override UnityEngine.Vector3 Operation(IEnumerable<UnityEngine.Vector3> values)
{
var defined = false;
var minimum = UnityEngine.Vector3.zero;
foreach (var value in values)
{
if (!defined)
{
minimum = value;
defined = true;
}
else
{
minimum = UnityEngine.Vector3.Min(minimum, value);
}
}
return minimum;
}
}
}

View File

@@ -0,0 +1,26 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the remainder of the component-wise division of two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Modulo")]
public sealed class Vector3Modulo : Modulo<Vector3>
{
protected override Vector3 defaultDividend => Vector3.zero;
protected override Vector3 defaultDivisor => Vector3.zero;
public override Vector3 Operation(Vector3 a, Vector3 b)
{
return new Vector3
(
a.x % b.x,
a.y % b.y,
a.z % b.z
);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Moves a 3D vector towards a target.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Move Towards")]
public sealed class Vector3MoveTowards : MoveTowards<Vector3>
{
protected override Vector3 defaultCurrent => Vector3.zero;
protected override Vector3 defaultTarget => Vector3.one;
public override Vector3 Operation(Vector3 current, Vector3 target, float maxDelta)
{
return Vector3.MoveTowards(current, target, maxDelta);
}
}
}

View File

@@ -0,0 +1,24 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise product of two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Multiply")]
public sealed class Vector3Multiply : Multiply<Vector3>
{
protected override Vector3 defaultB => Vector3.zero;
public override Vector3 Operation(Vector3 a, Vector3 b)
{
return new Vector3
(
a.x * b.x,
a.y * b.y,
a.z * b.z
);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the unit length version of a 3D vector.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Normalize")]
public sealed class Vector3Normalize : Normalize<UnityEngine.Vector3>
{
public override UnityEngine.Vector3 Operation(UnityEngine.Vector3 input)
{
return UnityEngine.Vector3.Normalize(input);
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the framerate-normalized value of a 3D vector.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Per Second")]
public sealed class Vector3PerSecond : PerSecond<Vector3>
{
public override Vector3 Operation(Vector3 input)
{
return input * Time.deltaTime;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the projection of a 3D vector on another.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Project")]
public sealed class Vector3Project : Project<UnityEngine.Vector3>
{
public override UnityEngine.Vector3 Operation(UnityEngine.Vector3 a, UnityEngine.Vector3 b)
{
return UnityEngine.Vector3.Project(a, b);
}
}
}

View File

@@ -0,0 +1,42 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Rounds each component of a 3D vector.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Round")]
public sealed class Vector3Round : Round<Vector3, Vector3>
{
protected override Vector3 Floor(Vector3 input)
{
return new Vector3
(
Mathf.Floor(input.x),
Mathf.Floor(input.y),
Mathf.Floor(input.z)
);
}
protected override Vector3 AwayFromZero(Vector3 input)
{
return new Vector3
(
Mathf.Round(input.x),
Mathf.Round(input.y),
Mathf.Round(input.z)
);
}
protected override Vector3 Ceiling(Vector3 input)
{
return new Vector3
(
Mathf.Ceil(input.x),
Mathf.Ceil(input.y),
Mathf.Ceil(input.z)
);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the difference between two 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Subtract")]
public sealed class Vector3Subtract : Subtract<Vector3>
{
protected override Vector3 defaultMinuend => Vector3.zero;
protected override Vector3 defaultSubtrahend => Vector3.zero;
public override Vector3 Operation(Vector3 a, Vector3 b)
{
return a - b;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two or more 3D vectors.
/// </summary>
[UnitCategory("Math/Vector 3")]
[UnitTitle("Add")]
public sealed class Vector3Sum : Sum<Vector3>, IDefaultValue<Vector3>
{
[DoNotSerialize]
public Vector3 defaultValue => Vector3.zero;
public override Vector3 Operation(Vector3 a, Vector3 b)
{
return a + b;
}
public override Vector3 Operation(IEnumerable<Vector3> values)
{
var sum = Vector3.zero;
foreach (var value in values)
{
sum += value;
}
return sum;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Add")]
[Obsolete("Use the new \"Add (Math/Vector 4)\" instead.")]
[RenamedFrom("Bolt.Vector4Add")]
[RenamedFrom("Unity.VisualScripting.Vector4Add")]
public sealed class DeprecatedVector4Add : Add<Vector4>
{
protected override Vector4 defaultB => Vector4.zero;
public override Vector4 Operation(Vector4 a, Vector4 b)
{
return a + b;
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns a version of a 4D vector where each component is positive.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Absolute")]
public sealed class Vector4Absolute : Absolute<Vector4>
{
protected override Vector4 Operation(Vector4 input)
{
return new Vector4(Mathf.Abs(input.x), Mathf.Abs(input.y), Mathf.Abs(input.z), Mathf.Abs(input.w));
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the average of two or more 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Average")]
public sealed class Vector4Average : Average<UnityEngine.Vector4>
{
public override UnityEngine.Vector4 Operation(UnityEngine.Vector4 a, UnityEngine.Vector4 b)
{
return (a + b) / 2;
}
public override UnityEngine.Vector4 Operation(IEnumerable<UnityEngine.Vector4> values)
{
var average = UnityEngine.Vector4.zero;
var count = 0;
foreach (var value in values)
{
average += value;
count++;
}
average /= count;
return average;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the distance between two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Distance")]
public sealed class Vector4Distance : Distance<UnityEngine.Vector4>
{
public override float Operation(UnityEngine.Vector4 a, UnityEngine.Vector4 b)
{
return UnityEngine.Vector4.Distance(a, b);
}
}
}

View File

@@ -0,0 +1,27 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise quotient of two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Divide")]
public sealed class Vector4Divide : Divide<Vector4>
{
protected override Vector4 defaultDividend => Vector4.zero;
protected override Vector4 defaultDivisor => Vector4.zero;
public override Vector4 Operation(Vector4 a, Vector4 b)
{
return new Vector4
(
a.x / b.x,
a.y / b.y,
a.z / b.z,
a.w / b.w
);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the dot product of two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Dot Product")]
public sealed class Vector4DotProduct : DotProduct<UnityEngine.Vector4>
{
public override float Operation(UnityEngine.Vector4 a, UnityEngine.Vector4 b)
{
return UnityEngine.Vector4.Dot(a, b);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the linear interpolation between two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Lerp")]
public sealed class Vector4Lerp : Lerp<Vector4>
{
protected override Vector4 defaultA => Vector4.zero;
protected override Vector4 defaultB => Vector4.one;
public override Vector4 Operation(Vector4 a, Vector4 b, float t)
{
return Vector4.Lerp(a, b, t);
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise maximum between two or more 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Maximum")]
public sealed class Vector4Maximum : Maximum<UnityEngine.Vector4>
{
public override UnityEngine.Vector4 Operation(UnityEngine.Vector4 a, UnityEngine.Vector4 b)
{
return UnityEngine.Vector4.Max(a, b);
}
public override UnityEngine.Vector4 Operation(IEnumerable<UnityEngine.Vector4> values)
{
var defined = false;
var maximum = UnityEngine.Vector4.zero;
foreach (var value in values)
{
if (!defined)
{
maximum = value;
defined = true;
}
else
{
maximum = UnityEngine.Vector4.Max(maximum, value);
}
}
return maximum;
}
}
}

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise minimum between two or more 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Minimum")]
public sealed class Vector4Minimum : Minimum<UnityEngine.Vector4>
{
public override UnityEngine.Vector4 Operation(UnityEngine.Vector4 a, UnityEngine.Vector4 b)
{
return UnityEngine.Vector4.Min(a, b);
}
public override UnityEngine.Vector4 Operation(IEnumerable<UnityEngine.Vector4> values)
{
var defined = false;
var minimum = UnityEngine.Vector4.zero;
foreach (var value in values)
{
if (!defined)
{
minimum = value;
defined = true;
}
else
{
minimum = UnityEngine.Vector4.Min(minimum, value);
}
}
return minimum;
}
}
}

View File

@@ -0,0 +1,27 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the remainder of the component-wise division of two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Modulo")]
public sealed class Vector4Modulo : Modulo<Vector4>
{
protected override Vector4 defaultDividend => Vector4.zero;
protected override Vector4 defaultDivisor => Vector4.zero;
public override Vector4 Operation(Vector4 a, Vector4 b)
{
return new Vector4
(
a.x % b.x,
a.y % b.y,
a.z % b.z,
a.w % b.w
);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Moves a 4D vector towards a target.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Move Towards")]
public sealed class Vector4MoveTowards : MoveTowards<Vector4>
{
protected override Vector4 defaultCurrent => Vector4.zero;
protected override Vector4 defaultTarget => Vector4.one;
public override Vector4 Operation(Vector4 current, Vector4 target, float maxDelta)
{
return Vector4.MoveTowards(current, target, maxDelta);
}
}
}

View File

@@ -0,0 +1,25 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the component-wise product of two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Multiply")]
public sealed class Vector4Multiply : Multiply<Vector4>
{
protected override Vector4 defaultB => Vector4.zero;
public override Vector4 Operation(Vector4 a, Vector4 b)
{
return new Vector4
(
a.x * b.x,
a.y * b.y,
a.z * b.z,
a.w * b.w
);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the unit length version of a 4D vector.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Normalize")]
public sealed class Vector4Normalize : Normalize<UnityEngine.Vector4>
{
public override UnityEngine.Vector4 Operation(UnityEngine.Vector4 input)
{
return UnityEngine.Vector4.Normalize(input);
}
}
}

View File

@@ -0,0 +1,17 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the framerate-normalized value of a 4D vector.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Per Second")]
public sealed class Vector4PerSecond : PerSecond<Vector4>
{
public override Vector4 Operation(Vector4 input)
{
return input * Time.deltaTime;
}
}
}

View File

@@ -0,0 +1,45 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Rounds each component of a 4D vector.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Round")]
public sealed class Vector4Round : Round<Vector4, Vector4>
{
protected override Vector4 Floor(Vector4 input)
{
return new Vector4
(
Mathf.Floor(input.x),
Mathf.Floor(input.y),
Mathf.Floor(input.z),
Mathf.Floor(input.w)
);
}
protected override Vector4 AwayFromZero(Vector4 input)
{
return new Vector4
(
Mathf.Round(input.x),
Mathf.Round(input.y),
Mathf.Round(input.z),
Mathf.Round(input.w)
);
}
protected override Vector4 Ceiling(Vector4 input)
{
return new Vector4
(
Mathf.Ceil(input.x),
Mathf.Ceil(input.y),
Mathf.Ceil(input.z),
Mathf.Ceil(input.w)
);
}
}
}

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the difference between two 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Subtract")]
public sealed class Vector4Subtract : Subtract<Vector4>
{
protected override Vector4 defaultMinuend => Vector4.zero;
protected override Vector4 defaultSubtrahend => Vector4.zero;
public override Vector4 Operation(Vector4 a, Vector4 b)
{
return a - b;
}
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.VisualScripting
{
/// <summary>
/// Returns the sum of two or more 4D vectors.
/// </summary>
[UnitCategory("Math/Vector 4")]
[UnitTitle("Add")]
public sealed class Vector4Sum : Sum<Vector4>, IDefaultValue<Vector4>
{
[DoNotSerialize]
public Vector4 defaultValue => Vector4.zero;
public override Vector4 Operation(Vector4 a, Vector4 b)
{
return a + b;
}
public override Vector4 Operation(IEnumerable<Vector4> values)
{
var sum = Vector4.zero;
foreach (var value in values)
{
sum += value;
}
return sum;
}
}
}