Skip to content

Commit 379af64

Browse files
committed
Auto addition of selections to comment block
1 parent 5859b38 commit 379af64

2 files changed

Lines changed: 41 additions & 13 deletions

File tree

Assets/Examples/BasicExample.asset

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ MonoBehaviour:
1818
- type: FloatNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
1919
jsonDatas: '{"GUID":"3327402b-5ad1-4564-af17-2025a850d4bb","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":242.0,"y":101.0,"width":73.0,"height":101.0},"expanded":false,"debug":false,"output":4.0}'
2020
- type: MultiAddNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
21-
jsonDatas: '{"GUID":"9a1c513a-65bc-4906-83b7-4a7b66699064","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":406.8500061035156,"y":121.50003051757813,"width":123.00001525878906,"height":101.0},"expanded":false,"debug":false,"output":0.0}'
21+
jsonDatas: '{"GUID":"9a1c513a-65bc-4906-83b7-4a7b66699064","computeOrder":2,"canProcess":true,"position":{"serializedVersion":"2","x":406.64605712890627,"y":244.3121337890625,"width":125.0,"height":101.0},"expanded":false,"debug":false,"output":0.0}'
2222
- type: SubNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
23-
jsonDatas: '{"GUID":"95bce55f-47d9-4c5d-bdcd-1f5bbbf57d1b","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":710.0,"y":200.0,"width":99.0,"height":101.0},"expanded":false,"debug":false,"inputA":0.0,"inputB":8.0,"output":-8.0}'
23+
jsonDatas: '{"GUID":"95bce55f-47d9-4c5d-bdcd-1f5bbbf57d1b","computeOrder":4,"canProcess":true,"position":{"serializedVersion":"2","x":709.6460571289063,"y":322.3121337890625,"width":98.0,"height":101.0},"expanded":false,"debug":false,"inputA":0.0,"inputB":8.0,"output":-8.0}'
2424
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
25-
jsonDatas: '{"GUID":"42eb43b8-ac7e-4f38-b49b-26ba1bc42732","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":879.1253051757813,"y":151.1937713623047,"width":107.0,"height":117.0},"expanded":false,"debug":false}'
25+
jsonDatas: '{"GUID":"42eb43b8-ac7e-4f38-b49b-26ba1bc42732","computeOrder":5,"canProcess":true,"position":{"serializedVersion":"2","x":879.1253051757813,"y":151.1937713623047,"width":107.0,"height":117.0},"expanded":false,"debug":false}'
2626
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
27-
jsonDatas: '{"GUID":"6398414c-0e45-44d7-a62f-3267016dbca1","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":236.43923950195313,"y":-42.947715759277347,"width":99.0,"height":115.0},"expanded":false,"debug":false}'
27+
jsonDatas: '{"GUID":"6398414c-0e45-44d7-a62f-3267016dbca1","computeOrder":2,"canProcess":true,"position":{"serializedVersion":"2","x":236.43923950195313,"y":-42.947715759277347,"width":99.0,"height":115.0},"expanded":false,"debug":false}'
2828
- type: PrefabNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
2929
jsonDatas: '{"GUID":"ffd2cf4b-87c3-42a6-9822-04bae7a5700b","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":478.04730224609377,"y":-235.4877471923828,"width":136.0,"height":223.00001525878907},"expanded":true,"debug":false,"output":{"instanceID":0}}'
3030
- type: FloatNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
@@ -33,9 +33,9 @@ MonoBehaviour:
3333
jsonDatas: '{"GUID":"ab7c80f0-51fd-401a-9d67-0b6543025f87","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":-104.5,"y":125.5,"width":73.0,"height":113.0},"expanded":false,"debug":false,"output":"Hello
3434
World"}'
3535
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
36-
jsonDatas: '{"GUID":"e277d5c6-386e-4f6b-bd63-af2353f3e4d8","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":68.76971435546875,"y":94.11068725585938,"width":107.0,"height":117.0},"expanded":false,"debug":false}'
36+
jsonDatas: '{"GUID":"e277d5c6-386e-4f6b-bd63-af2353f3e4d8","computeOrder":2,"canProcess":true,"position":{"serializedVersion":"2","x":68.76971435546875,"y":94.11068725585938,"width":107.0,"height":117.0},"expanded":false,"debug":false}'
3737
- type: FloatNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
38-
jsonDatas: '{"GUID":"34e17a0c-9187-47eb-a21c-d105ee6ed911","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":506.0,"y":309.04254150390627,"width":107.0,"height":117.0},"expanded":true,"debug":false,"output":8.0}'
38+
jsonDatas: '{"GUID":"34e17a0c-9187-47eb-a21c-d105ee6ed911","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":505.64605712890627,"y":431.3121337890625,"width":73.0,"height":101.0},"expanded":true,"debug":false,"output":8.0}'
3939
- type: ParameterNode, com.alelievr.NodeGraphProcessor, Version=0.0.0.0, Culture=neutral,
4040
PublicKeyToken=null
4141
jsonDatas: '{"GUID":"eb62aec1-6b04-49a1-89c4-27d66f83289d","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":631.0,"y":6.160011291503906,"width":88.0,"height":77.0},"expanded":false,"debug":false,"parameterGUID":"4f5bc9d8-e5d3-4935-8d09-5cf903694414"}'
@@ -88,7 +88,20 @@ MonoBehaviour:
8888
outputFieldName: output
8989
inputPortIdentifier:
9090
outputPortIdentifier:
91-
commentBlocks: []
91+
commentBlocks:
92+
- title: New Comment Block
93+
color: {r: 0, g: 0, b: 0, a: 0}
94+
position:
95+
serializedVersion: 2
96+
x: 381.64612
97+
y: 164.31215
98+
width: 451
99+
height: 392.99997
100+
size: {x: 300, y: 100}
101+
innerNodeGUIDs:
102+
- 9a1c513a-65bc-4906-83b7-4a7b66699064
103+
- 95bce55f-47d9-4c5d-bdcd-1f5bbbf57d1b
104+
- 34e17a0c-9187-47eb-a21c-d105ee6ed911
92105
pinnedElements:
93106
- position:
94107
serializedVersion: 2
@@ -119,5 +132,5 @@ MonoBehaviour:
119132
serializedName:
120133
serializedValue: 0
121134
input: 1
122-
position: {x: 229, y: 93, z: 0}
123-
scale: {x: 0.7561437, y: 0.7561437, z: 1}
135+
position: {x: 421, y: 215, z: 0}
136+
scale: {x: 0.65751624, y: 0.65751624, z: 1}

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseGraphView.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
260260
protected void BuildCreateContextualMenu(ContextualMenuPopulateEvent evt)
261261
{
262262
Vector2 position = evt.mousePosition - (Vector2)viewTransform.position;
263-
evt.menu.AppendAction("Create/Comment Block", (e) => AddCommentBlock(new CommentBlock("New Comment Block", position)), DropdownMenuAction.AlwaysEnabled);
263+
evt.menu.AppendAction("Create/Comment Block", (e) => AddSelectionsToCommentBlock(AddCommentBlock(new CommentBlock("New Comment Block", position))), DropdownMenuAction.AlwaysEnabled);
264264
}
265265

266266
protected void BuildViewContextualMenu(ContextualMenuPopulateEvent evt)
@@ -489,14 +489,14 @@ void RemoveNodeViews()
489489
nodeViewsPerNode.Clear();
490490
}
491491

492-
public void AddCommentBlock(CommentBlock block)
492+
public CommentBlockView AddCommentBlock(CommentBlock block)
493493
{
494494
graph.AddCommentBlock(block);
495495
block.OnCreated();
496-
AddCommentBlockView(block);
496+
return AddCommentBlockView(block);
497497
}
498498

499-
public void AddCommentBlockView(CommentBlock block)
499+
public CommentBlockView AddCommentBlockView(CommentBlock block)
500500
{
501501
var c = new CommentBlockView();
502502

@@ -505,8 +505,23 @@ public void AddCommentBlockView(CommentBlock block)
505505
AddElement(c);
506506

507507
commentBlockViews.Add(c);
508+
return c;
508509
}
509510

511+
public void AddSelectionsToCommentBlock(CommentBlockView view)
512+
{
513+
foreach (var selectedNode in selection)
514+
{
515+
if (selectedNode is BaseNodeView)
516+
{
517+
if (commentBlockViews.Exists(x => x.ContainsElement(selectedNode as BaseNodeView)))
518+
continue;
519+
520+
view.AddElement(selectedNode as BaseNodeView);
521+
}
522+
}
523+
}
524+
510525
public void RemoveCommentBlocks()
511526
{
512527
foreach (var commentBlockView in commentBlockViews)

0 commit comments

Comments
 (0)