Skip to content

Commit 7812566

Browse files
committed
Add example conversion node
1 parent 3747551 commit 7812566

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Globalization;
3+
using GraphProcessor;
4+
using UnityEngine;
5+
6+
[Serializable, NodeMenuItem("Convert/Float to String"), ConverterNode(typeof(float), typeof(string))]
7+
public class FloatToStringsNode : BaseNode, IConversionNode
8+
{
9+
[Input("In")]
10+
public float input;
11+
12+
public int decimalPlaces = 2;
13+
14+
[Output("Out")]
15+
public string output;
16+
17+
public override string name => "To String";
18+
19+
public string GetConversionInput()
20+
{
21+
return nameof(input);
22+
}
23+
24+
public string GetConversionOutput()
25+
{
26+
return nameof(output);
27+
}
28+
29+
protected override void Process()
30+
{
31+
var mult = Mathf.Pow(10, decimalPlaces);
32+
float val = Mathf.Round(input * mult) / mult;
33+
output = val.ToString(CultureInfo.InvariantCulture);
34+
}
35+
}

Assets/Examples/DefaultNodes/Nodes/FloatToStringNode.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)