Skip to content

Commit 65c1b43

Browse files
committed
Nanoid removed, using guid instead
removed commented out code blocks removed unused components and utility methods
1 parent ba27dca commit 65c1b43

25 files changed

+120
-1589
lines changed

.DS_Store

0 Bytes
Binary file not shown.
File renamed without changes.

Assets/Resources/graph.json

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,70 @@
22
"name": "awesome graph",
33
"nodes": [
44
{
5-
"id": "qLDZQ9hxsJ",
6-
"values": [
7-
{
8-
"key": "floatValue",
9-
"value": "2"
10-
}
11-
],
12-
"posX": -285.0,
13-
"posY": 5.0,
14-
"path": "Prefabs/Nodes/FloatNode",
15-
"inputSocketIds": [],
16-
"outputSocketIds": [
17-
"wnMHDn3zg8"
18-
]
19-
},
20-
{
21-
"id": "a3bnBwNB-F",
5+
"id": "GfdjzUd9MU",
226
"values": [
237
{
248
"key": "floatValue",
259
"value": "3"
2610
}
2711
],
28-
"posX": -280.0,
29-
"posY": -169.0,
12+
"posX": -232.33334350585938,
13+
"posY": 114.99994659423828,
3014
"path": "Prefabs/Nodes/FloatNode",
3115
"inputSocketIds": [],
3216
"outputSocketIds": [
33-
"cOL7umElvR"
17+
"JLumt0-LVM"
3418
]
3519
},
3620
{
37-
"id": "5mMygTJy-U",
21+
"id": "jpUTNTwlum",
3822
"values": [
3923
{
4024
"key": "outputValue",
41-
"value": "5"
25+
"value": "6"
4226
},
4327
{
4428
"key": "opType",
45-
"value": "2"
29+
"value": "0"
4630
}
4731
],
48-
"posX": 204.0,
49-
"posY": 114.0,
32+
"posX": 122.66664123535156,
33+
"posY": -38.33336639404297,
5034
"path": "Prefabs/Nodes/MathOperationNode",
5135
"inputSocketIds": [
52-
"uQlx5u7yAC"
53-
],
54-
"outputSocketIds": [
55-
"xcfe2BLcNy"
56-
]
57-
},
58-
{
59-
"id": "Ka8tAI1omD",
60-
"values": [
61-
{
62-
"key": "floatValue",
63-
"value": "0"
64-
}
36+
"qveZxiOoY2"
6537
],
66-
"posX": -5.0,
67-
"posY": -139.0,
68-
"path": "Prefabs/Nodes/FloatNode",
69-
"inputSocketIds": [],
7038
"outputSocketIds": [
71-
"Xt3AhfllfC"
39+
"LXfeinny7g"
7240
]
7341
},
7442
{
75-
"id": "cXJzfgkI-h",
43+
"id": "0zBYK7K09J",
7644
"values": [
7745
{
7846
"key": "floatValue",
79-
"value": "0"
47+
"value": "2"
8048
}
8149
],
82-
"posX": 333.0,
83-
"posY": -47.0,
50+
"posX": -214.0,
51+
"posY": -33.333396911621097,
8452
"path": "Prefabs/Nodes/FloatNode",
8553
"inputSocketIds": [],
8654
"outputSocketIds": [
87-
"wxDYuucleS"
55+
"TmR2b7u3UN"
8856
]
8957
}
9058
],
9159
"connections": [
9260
{
93-
"id": "kPaeazM5E1",
94-
"outputSocketId": "wnMHDn3zg8",
95-
"inputSocketId": "uQlx5u7yAC"
96-
},
97-
{
98-
"id": "Fq0F_ErsbY",
99-
"outputSocketId": "cOL7umElvR",
100-
"inputSocketId": "uQlx5u7yAC"
61+
"id": "OM8y0UbW-x",
62+
"outputSocketId": "JLumt0-LVM",
63+
"inputSocketId": "qveZxiOoY2"
10164
},
10265
{
103-
"id": "el5-9KiQ9b",
104-
"outputSocketId": "Xt3AhfllfC",
105-
"inputSocketId": "uQlx5u7yAC"
66+
"id": "DJcBuiEmyJ",
67+
"outputSocketId": "TmR2b7u3UN",
68+
"inputSocketId": "qveZxiOoY2"
10669
}
10770
]
10871
}

Assets/RuntimeNodeEditor/Scripts/BezierCurveDrawer.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,26 @@ namespace RuntimeNodeEditor
66
{
77
public class BezierCurveDrawer : MonoBehaviour
88
{
9-
10-
119
public RectTransform pointerLocator;
1210
public RectTransform lineContainer;
1311
[Header("Bezier settings")]
1412
public float vertexCount = 60;
1513

16-
private static UILineRendererWithListener _lineRenderer;
17-
private static bool _hasRequest;
18-
private static Socket _draggingSocket;
14+
private static RectTransform _lineContainer;
15+
private static RectTransform _pointerLocator;
16+
private static UILineRendererWithListener _lineRenderer;
17+
private static bool _hasRequest;
18+
private static Socket _draggingSocket;
1919
private static Dictionary<string, ConnectionDrawData> _connections;
20-
private static RectTransform _lineContainer;
21-
private static RectTransform _pointerLocator;
2220

2321

2422
public void Init()
2523
{
26-
_connections = new Dictionary<string, ConnectionDrawData>();
27-
_lineContainer = lineContainer;
24+
_connections = new Dictionary<string, ConnectionDrawData>();
25+
_lineContainer = lineContainer;
2826
_pointerLocator = pointerLocator;
29-
_lineRenderer = CreateLine();
30-
_hasRequest = false;
27+
_lineRenderer = CreateLine();
28+
_hasRequest = false;
3129

3230
CancelDrag();
3331
}
@@ -97,13 +95,13 @@ private void DrawConnection(SocketHandle port1, SocketHandle port2, UILineRender
9795
private static void DrawDragging(SocketHandle port)
9896
{
9997
Vector2 localPointerPos;
100-
#if ENABLE_LEGACY_INPUT_MANAGER
98+
#if ENABLE_LEGACY_INPUT_MANAGER
10199
RectTransformUtility.ScreenPointToLocalPointInRectangle(_lineContainer, Input.mousePosition, null, out localPointerPos);
102-
#endif
103-
#if ENABLE_INPUT_SYSTEM
100+
#endif
101+
#if ENABLE_INPUT_SYSTEM
104102
var mousePosition = UnityEngine.InputSystem.Mouse.current.position.ReadValue();
105103
RectTransformUtility.ScreenPointToLocalPointInRectangle(_lineContainer, mousePosition, null, out localPointerPos);
106-
#endif
104+
#endif
107105
_pointerLocator.localPosition = localPointerPos;
108106

109107
var pointList = new List<Vector2>();

Assets/RuntimeNodeEditor/Scripts/ContextMenu/ContextMenuBuilder.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@ public ContextMenuBuilder()
1313

1414
public ContextMenuBuilder Add(string name)
1515
{
16-
//_root.children.Add(new ContextMenuData(name)
17-
//{
18-
// parent = _root,
19-
//});
2016
BuildHierarchy(name);
2117
return this;
2218
}
2319

2420
public ContextMenuBuilder Add(string name, Action callback)
2521
{
26-
//_root.children.Add(new ContextMenuData(name)
27-
//{
28-
// parent = _root,
29-
// callback = callback
30-
//});
3122
BuildHierarchy(name).callback = callback;
3223
return this;
3324
}

Assets/RuntimeNodeEditor/Scripts/Graph/GraphPointerListener.cs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace RuntimeNodeEditor
1212
public class GraphPointerListener : MonoBehaviour, IPointerClickHandler, IDragHandler
1313
{
1414

15-
private RectTransform _rectTransform;
16-
private Vector2 _zoomCenterPos;
17-
private float _currentZoom;
18-
private float _mouseWheelSensitivity;
19-
private float _minZoom;
20-
private float _maxZoom;
15+
private RectTransform _rectTransform;
16+
private Vector2 _zoomCenterPos;
17+
private float _currentZoom;
18+
private float _mouseWheelSensitivity;
19+
private float _minZoom;
20+
private float _maxZoom;
2121

2222
public event Action<PointerEventData> GraphPointerClickEvent;
2323
public event Action<PointerEventData> GraphPointerDragEvent;
@@ -41,44 +41,27 @@ public void OnDrag(PointerEventData eventData)
4141
GraphPointerDragEvent?.Invoke(eventData);
4242
}
4343

44-
// private void ConstraitPosition()
45-
// {
46-
// RectTransform rectTransform = (RectTransform)transform;
47-
48-
// RectTransform parentTransform = (RectTransform)rectTransform.parent;
49-
// Vector2 viewportSize = new Vector2(parentTransform.rect.width, parentTransform.rect.height);
50-
// Vector2 contentSize = new Vector2(rectTransform.rect.width, rectTransform.rect.height);
51-
52-
// Vector2 dragMax = new Vector2(0, rectTransform.sizeDelta.y - viewportSize.y);
53-
// Vector2 dragMin = new Vector2(-(rectTransform.sizeDelta.x - viewportSize.x), 0);
54-
55-
// rectTransform.anchoredPosition = new Vector2(
56-
// Mathf.Min(Mathf.Max(dragMin.x, rectTransform.anchoredPosition.x), dragMax.x),
57-
// Mathf.Min(Mathf.Max(dragMin.y, rectTransform.anchoredPosition.y), dragMax.y)
58-
// );
59-
// }
60-
6144
public void OnUpdate()
6245
{
6346
//pc input
6447
float scrollWheelInput = 0;
65-
#if ENABLE_LEGACY_INPUT_MANAGER
48+
#if ENABLE_LEGACY_INPUT_MANAGER
6649
scrollWheelInput = Input.mouseScrollDelta.y;
67-
#endif
68-
#if ENABLE_INPUT_SYSTEM
50+
#endif
51+
#if ENABLE_INPUT_SYSTEM
6952
scrollWheelInput = Mouse.current.scroll.y.ReadValue() * 0.001f; // Magic Number to match Input scroll values
70-
#endif
53+
#endif
7154

7255
if (Mathf.Abs(scrollWheelInput) > float.Epsilon)
7356
{
7457
_currentZoom *= 1 + scrollWheelInput * _mouseWheelSensitivity;
7558
_currentZoom = Mathf.Clamp(_currentZoom, _minZoom, _maxZoom);
76-
#if ENABLE_LEGACY_INPUT_MANAGER
59+
#if ENABLE_LEGACY_INPUT_MANAGER
7760
_zoomCenterPos = (Vector2)Input.mousePosition;
78-
#endif
79-
#if ENABLE_INPUT_SYSTEM
61+
#endif
62+
#if ENABLE_INPUT_SYSTEM
8063
_zoomCenterPos = Mouse.current.position.ReadValue();
81-
#endif
64+
#endif
8265

8366
Vector2 beforePointInContent;
8467
RectTransformUtility.ScreenPointToLocalPointInRectangle(_rectTransform, _zoomCenterPos, null, out beforePointInContent);

Assets/RuntimeNodeEditor/Scripts/Graph/NodeGraph.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,33 @@ namespace RuntimeNodeEditor
77
{
88
public class NodeGraph : MonoBehaviour
99
{
10-
public RectTransform contextMenuContainer;
11-
public RectTransform nodeContainer;
10+
// scene references
11+
public RectTransform contextMenuContainer;
12+
public RectTransform nodeContainer;
1213
public GraphPointerListener pointerListener;
14+
public BezierCurveDrawer drawer;
1315

14-
public List<Node> nodes;
15-
public List<Connection> connections;
16-
17-
// scene references
18-
public BezierCurveDrawer drawer;
16+
public List<Node> nodes;
17+
public List<Connection> connections;
1918

2019
// cache
21-
private SocketOutput _currentDraggingSocket;
22-
private Vector2 _pointerOffset;
23-
private Vector2 _localPointerPos;
24-
private Vector2 _duplicateOffset;
25-
private RectTransform _nodeContainer;
26-
private RectTransform _graphContainer;
20+
private SocketOutput _currentDraggingSocket;
21+
private Vector2 _pointerOffset;
22+
private Vector2 _localPointerPos;
23+
private Vector2 _duplicateOffset;
24+
private RectTransform _nodeContainer;
25+
private RectTransform _graphContainer;
2726

2827
public RectTransform GraphContainer => _graphContainer;
2928

3029

3130
public void Init()
3231
{
33-
_nodeContainer = nodeContainer;
34-
_graphContainer = this.GetComponent<RectTransform>();
35-
nodes = new List<Node>();
36-
connections = new List<Connection>();
37-
_duplicateOffset = (Vector2.one * 10f);
32+
_nodeContainer = nodeContainer;
33+
_graphContainer = this.GetComponent<RectTransform>();
34+
_duplicateOffset = (Vector2.one * 10f);
35+
nodes = new List<Node>();
36+
connections = new List<Connection>();
3837

3938
SignalSystem.OutputSocketDragStartEvent += OnOutputDragStarted;
4039
SignalSystem.OutputSocketDragDrop += OnOutputDragDroppedTo;
@@ -49,12 +48,12 @@ public void Init()
4948
public void Create(string prefabPath)
5049
{
5150
var mousePosition = Vector2.zero;
52-
#if ENABLE_LEGACY_INPUT_MANAGER
51+
#if ENABLE_LEGACY_INPUT_MANAGER
5352
mousePosition = Input.mousePosition;
54-
#endif
55-
#if ENABLE_INPUT_SYSTEM
53+
#endif
54+
#if ENABLE_INPUT_SYSTEM
5655
mousePosition = UnityEngine.InputSystem.Mouse.current.position.ReadValue();
57-
#endif
56+
#endif
5857
var pos = Utility.GetLocalPointIn(nodeContainer, mousePosition);
5958
var node = Utility.CreateNodePrefab<Node>(prefabPath);
6059
node.Init(pos, CreateId, prefabPath);
@@ -412,6 +411,6 @@ private void LoadConn(ConnectionData data)
412411
}
413412
}
414413

415-
private string CreateId => Nanoid.Nanoid.Generate(size: 10);
414+
private string CreateId => System.Guid.NewGuid().ToString();
416415
}
417416
}

0 commit comments

Comments
 (0)