Skip to content

Commit

Permalink
Update Negate.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
S2NX7 authored Aug 4, 2023
1 parent 032de64 commit 96aaf35
Showing 1 changed file with 60 additions and 9 deletions.
69 changes: 60 additions & 9 deletions Runtime/Fundamentals/Nodes/Math/Negate.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,80 @@
using UnityEngine;
using Unity.VisualScripting;
using System.Numerics;
using UnityEngine.Windows;

[UnitTitle("Negate Value")] // Node title
[UnitTitle("Negate")] // Node title
[UnitCategory("Community\\Math")] // Node category
[TypeIcon(typeof(Negate))] // Node category
public class NegativeValueNode : Unit
{
[UnitHeaderInspectable]
[Inspectable]
public NegateType type;
[DoNotSerialize]
public ValueInput input;
public ValueInput Float;
[DoNotSerialize]
public ValueInput Int;
[DoNotSerialize]
public ValueInput Vector2;
[DoNotSerialize]
public ValueInput Vector3;

[DoNotSerialize]
public ValueOutput output;

protected override void Definition()
{
input = ValueInput<float>(nameof(input));
output = ValueOutput(nameof(output), GetNegativeValue);
switch (type)
{
case NegateType.Float:
Float = ValueInput<float>(nameof(Float));
break;
case NegateType.Int:
Int = ValueInput<int>(nameof(Int));
break;
case NegateType.Vector2:
Vector2 = ValueInput<UnityEngine.Vector2>(nameof(Vector2));
break;
case NegateType.Vector3:
Vector3 = ValueInput<UnityEngine.Vector3>(nameof(Vector3));
break;
default:
Float = ValueInput<float>(nameof(Float));
break;
}

Requirement(input, output);
output = ValueOutput(nameof(output), GetNegativeValue);
}

private float GetNegativeValue(Flow flow)
private object GetNegativeValue(Flow flow)
{
// Get the value from the input port and negate it
float value = flow.GetValue<float>(input);
return -value;
switch (type)
{
case NegateType.Float:
float floatvalue = flow.GetValue<float>(Float);
return -floatvalue;
case NegateType.Int:
int intvalue = flow.GetValue<int>(Int);
return -intvalue;
case NegateType.Vector2:
UnityEngine.Vector2 vector2value = flow.GetValue<UnityEngine.Vector2>(Vector2);
return -vector2value;
case NegateType.Vector3:
UnityEngine.Vector3 vector3value = flow.GetValue<UnityEngine.Vector3>(Vector3);
return -vector3value;
default:
float value = flow.GetValue<float>(Float);
return -value;
}

}
}

public enum NegateType
{
Float,
Int,
Vector2,
Vector3,
}

0 comments on commit 96aaf35

Please sign in to comment.