-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |