Skip to content

Commit 3c6ac10

Browse files
committed
Graph size setter added
Drawer color setter added
1 parent 81d6de0 commit 3c6ac10

File tree

4 files changed

+147
-5
lines changed

4 files changed

+147
-5
lines changed

Assets/Examples/2_SimpleMathEditor/Scripts/ExampleNodeEditor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public override void StartEditor(NodeGraph graph)
1818
Events.OnGraphPointerClickEvent += OnGraphPointerClick;
1919
Events.OnNodePointerClickEvent += OnNodePointerClick;
2020
Events.OnConnectionPointerClickEvent += OnNodeConnectionPointerClick;
21+
Events.OnSocketConnect += OnConnect;
22+
23+
Graph.SetSize(Vector2.one * 20000);
24+
}
25+
26+
private void OnConnect(SocketInput arg1, SocketOutput arg2)
27+
{
28+
Graph.drawer.SetConnectionColor(arg2.connection.connId, Color.green);
2129
}
2230

2331
private void OnGraphPointerClick(PointerEventData eventData)

Assets/RuntimeNodeEditor/Scripts/Graph/BezierCurveDrawer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace RuntimeNodeEditor
66
{
77
public class BezierCurveDrawer : MonoBehaviour
88
{
9+
public UILineRendererWithListener RequestLine { get { return _lineRenderer; } }
10+
911
public RectTransform pointerLocator;
1012
public RectTransform lineContainer;
1113
[Header("Bezier settings")]
@@ -77,6 +79,10 @@ public void CancelDrag()
7779
_lineRenderer.gameObject.SetActive(_hasRequest);
7880
}
7981

82+
public void SetConnectionColor(string connId, Color color)
83+
{
84+
_connections[connId].lineRenderer.color = color;
85+
}
8086
// drawing
8187
private void DrawConnection(SocketHandle port1, SocketHandle port2, UILineRendererWithListener lineRenderer)
8288
{

Assets/RuntimeNodeEditor/Scripts/Graph/NodeGraph.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ namespace RuntimeNodeEditor
88
{
99
public class NodeGraph : MonoBehaviour
1010
{
11-
public RectTransform GraphContainer => _graphContainer;
12-
public GraphPointerListener GraphPointerListener => pointerListener;
11+
public RectTransform GraphContainer => _graphContainer;
1312

1413
// scene references
1514
public RectTransform contextMenuContainer;
@@ -60,6 +59,11 @@ public void Init(SignalSystem signalSystem, float minZoom, float maxZoom)
6059
drawer.Init(_signalSystem);
6160
}
6261

62+
public void SetSize(Vector2 size)
63+
{
64+
_graphContainer.sizeDelta = size;
65+
}
66+
6367
public void Create(string prefabPath)
6468
{
6569
var mousePosition = Utility.GetMousePosition();
@@ -102,9 +106,9 @@ public void Connect(SocketInput input, SocketOutput output)
102106

103107
connections.Add(connection);
104108
input.OwnerNode.Connect(input, output);
109+
drawer.Add(connection.connId, output.handle, input.handle);
105110

106111
_signalSystem.InvokeSocketConnection(input, output);
107-
drawer.Add(connection.connId, output.handle, input.handle);
108112
}
109113

110114
public void Disconnect(Connection conn)

Assets/docs/documentation.md

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,133 @@ public class MyNodeEditor : NodeEditor
474474
```
475475

476476

477-
## How to create a node
478-
## How to serialize a graph
479477
## Make your custom node
478+
479+
1. Create a class
480+
481+
```c#
482+
public class MyCustomNode : Node
483+
{
484+
// define ui objects
485+
486+
// define connection sockets
487+
488+
public override void Setup()
489+
{
490+
// make your initializations
491+
}
492+
}
493+
```
494+
495+
> `OnSerialize` and `OnDeserialize` methods are needed for serialization. Also node duplication from graph also relies on this methods. Otherwise graph serialization won't work.
496+
497+
498+
2. Create a prefab
499+
3. Place it in Resources folder
500+
501+
502+
480503
## Make your custom graph
481504

505+
### Overriding NodeGraph
506+
507+
NodeGraph is the core part of the system. It responsible for nodes, connections and listening pointer events. If your graph requires custom behaviors, graph can be override.
508+
509+
```c#
510+
public class CustomGraph : NodeGraph
511+
{
512+
513+
}
514+
```
515+
516+
### Graph Prefab
517+
518+
To start the editor you need to provide a graph.
519+
520+
521+
522+
523+
## Make your custom context menu
524+
## How to create a node
525+
526+
Simply call `Create(string path)` method from `NodeGraph`.
527+
528+
```c#
529+
public class MyNodeEditor : NodeEditor
530+
{
531+
...
532+
private void CreateANode()
533+
{
534+
Graph.Create("path/to/prefab/from/Resources");
535+
}
536+
}
537+
```
538+
539+
540+
541+
542+
## How to serialize a graph
543+
544+
RuntimeNodeEditor provides a simple serialization.
545+
546+
```c#
547+
548+
// extract the serialized graph data as json
549+
var graphData = Graph.ExportJson();
550+
551+
// save as json file to path
552+
Grap.Save("path/to/file");
553+
554+
```
555+
556+
Let's take a look at serialized json.
557+
558+
559+
```json
560+
{
561+
"nodes": [
562+
563+
],
564+
"connections": [
565+
{
566+
"id": "a979fb29-4643-4479-bb7a-38e5e70b7efa",
567+
"outputSocketId": "fc88d4ab-bbdf-4219-b661-40a5d474567d",
568+
"inputSocketId": "e5fbbf79-8c6f-43e7-80cd-61a39b8938e3"
569+
}
570+
]
571+
}
572+
```
573+
574+
575+
576+
482577
## Example editors in project
578+
579+
580+
581+
582+
583+
584+
585+
586+
587+
588+
589+
590+
591+
592+
593+
594+
595+
596+
597+
598+
599+
600+
601+
602+
603+
604+
605+
606+

0 commit comments

Comments
 (0)