Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Examples.meta → Assets/Samples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Samples/Runtime Node Editor/1.0.0.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Samples/Runtime Node Editor/1.0.0/Color Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Cemuka.RuntimeNodeEditor.Samples.ColorEditor",
"rootNamespace": "",
"references": [
"GUID:8f5c68f774363a54c99fc0044d54659f",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Cemuka.RuntimeNodeEditor.Samples.SimpleMathEditor",
"rootNamespace": "",
"references": [
"GUID:8f5c68f774363a54c99fc0044d54659f",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
using System.Collections.Generic;
using System.Linq;
namespace RuntimeNodeEditor.Examples
{
public class MathOperationNode : Node
{
public TMP_Text resultText;
public TMP_Dropdown dropdown;
public SocketInput inputSocket;
public SocketOutput outputSocket;
private List<IOutput> _incomingOutputs;
public override void Setup()
{
_incomingOutputs = new List<IOutput>();
Register(outputSocket);
Register(inputSocket);
SetHeader("operation");
outputSocket.SetValue(0f);
dropdown.AddOptions(new List<TMP_Dropdown.OptionData>()
{
new TMP_Dropdown.OptionData(MathOperations.Multiply.ToString()),
new TMP_Dropdown.OptionData(MathOperations.Divide.ToString()),
new TMP_Dropdown.OptionData(MathOperations.Add.ToString()),
new TMP_Dropdown.OptionData(MathOperations.Subtract.ToString())
});
dropdown.onValueChanged.AddListener(selected =>
{
OnConnectedValueUpdated();
});
OnConnectionEvent += OnConnection;
OnDisconnectEvent += OnDisconnect;
}
public void OnConnection(SocketInput input, IOutput output)
{
output.ValueUpdated += OnConnectedValueUpdated;
_incomingOutputs.Add(output);
OnConnectedValueUpdated();
}
public void OnDisconnect(SocketInput input, IOutput output)
{
output.ValueUpdated -= OnConnectedValueUpdated;
_incomingOutputs.Remove(output);
OnConnectedValueUpdated();
}
public override void OnSerialize(Serializer serializer)
{
var output = outputSocket.GetValue<float>();
serializer.Add("opType", dropdown.value.ToString());
}
public override void OnDeserialize(Serializer serializer)
{
var opType = int.Parse(serializer.Get("opType"));
dropdown.SetValueWithoutNotify(opType);
OnConnectedValueUpdated();
}
private void OnConnectedValueUpdated()
{
List<float> incomingValues = new List<float>();
foreach (var c in _incomingOutputs)
{
incomingValues.Add(c.GetValue<float>());
}
float result = Calculate(incomingValues);
outputSocket.SetValue(result);
Display(result.ToString());
}
private void Display(string text)
{
resultText.text = text;
}
private float Calculate(List<float> values)
{
if (values.Count > 0)
{
var operation = (MathOperations)dropdown.value;
switch (operation)
{
default: return values.Aggregate((x, y) => x * y);
case MathOperations.Divide: return values.Aggregate((x, y) => x / y);
case MathOperations.Add: return values.Aggregate((x, y) => x + y);
case MathOperations.Subtract: return values.Aggregate((x, y) => x - y);
}
}
else
{
return 0;
}
}
}
}
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
using System.Collections.Generic;
using System.Linq;

namespace RuntimeNodeEditor.Examples
{
public class MathOperationNode : Node
{
public TMP_Text resultText;
public TMP_Dropdown dropdown;
public SocketInput inputSocket;
public SocketOutput outputSocket;

private List<IOutput> _incomingOutputs;


public override void Setup()
{
_incomingOutputs = new List<IOutput>();

Register(outputSocket);
Register(inputSocket);

SetHeader("operation");
outputSocket.SetValue(0f);

dropdown.AddOptions(new List<TMP_Dropdown.OptionData>()
{
new TMP_Dropdown.OptionData(MathOperations.Multiply.ToString()),
new TMP_Dropdown.OptionData(MathOperations.Divide.ToString()),
new TMP_Dropdown.OptionData(MathOperations.Add.ToString()),
new TMP_Dropdown.OptionData(MathOperations.Subtract.ToString())
});

dropdown.onValueChanged.AddListener(selected =>
{
OnConnectedValueUpdated();
});

OnConnectionEvent += OnConnection;
OnDisconnectEvent += OnDisconnect;
}

public void OnConnection(SocketInput input, IOutput output)
{
output.ValueUpdated += OnConnectedValueUpdated;
_incomingOutputs.Add(output);

OnConnectedValueUpdated();
}

public void OnDisconnect(SocketInput input, IOutput output)
{
output.ValueUpdated -= OnConnectedValueUpdated;
_incomingOutputs.Remove(output);

OnConnectedValueUpdated();
}

public override void OnSerialize(Serializer serializer)
{
var output = outputSocket.GetValue<float>();
serializer.Add("opType", dropdown.value.ToString());
}

public override void OnDeserialize(Serializer serializer)
{
var opType = int.Parse(serializer.Get("opType"));
dropdown.SetValueWithoutNotify(opType);

OnConnectedValueUpdated();
}

private void OnConnectedValueUpdated()
{
List<float> incomingValues = new List<float>();
foreach (var c in _incomingOutputs)
{
incomingValues.Add(c.GetValue<float>());
}

float result = Calculate(incomingValues);
outputSocket.SetValue(result);
Display(result.ToString());
}

private void Display(string text)
{
resultText.text = text;
}

private float Calculate(List<float> values)
{
if (values.Count > 0)
{
var operation = (MathOperations)dropdown.value;
switch (operation)
{
default: return values.Aggregate((x, y) => x * y);
case MathOperations.Divide: return values.Aggregate((x, y) => x / y);
case MathOperations.Add: return values.Aggregate((x, y) => x + y);
case MathOperations.Subtract: return values.Aggregate((x, y) => x - y);
}
}
else
{
return 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@ public enum MathOperations
Add,
Subtract
}

public enum ConnectionType
{
Single,
Multiple
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading