1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Properly fixed GroupNode size and added grouped reroute selection

This commit is contained in:
Oli 2023-01-12 20:42:58 +00:00
parent 2cc9084955
commit 0eb52dd626
3 changed files with 33 additions and 9 deletions

View File

@ -4,6 +4,7 @@ using UnityEngine;
using XNode; using XNode;
using System.Linq; using System.Linq;
using UnityEditor; using UnityEditor;
using XNodeEditor.Internal;
namespace XNodeEditor namespace XNodeEditor
{ {
@ -13,6 +14,7 @@ namespace XNodeEditor
private static Vector4 padding = new Vector4(32, 48, 32, 32); private static Vector4 padding = new Vector4(32, 48, 32, 32);
private bool _selected = false; private bool _selected = false;
private UnityEngine.Object[] lastSelection; private UnityEngine.Object[] lastSelection;
private List<RerouteReference> lastSelectionReroutes;
public override void OnHeaderGUI() public override void OnHeaderGUI()
{ {
@ -24,7 +26,8 @@ namespace XNodeEditor
_selected = true; _selected = true;
var selection = Selection.objects.ToList(); var selection = Selection.objects.ToList();
lastSelection = selection.ToArray(); lastSelection = selection.ToArray();
GetChildren(node, ref selection); lastSelectionReroutes = new List<RerouteReference>(window.selectedReroutes);
SelectChildren(node, ref selection);
//selection.AddRange(GetChildren(node)); //selection.AddRange(GetChildren(node));
Selection.objects = selection.Distinct().ToArray(); Selection.objects = selection.Distinct().ToArray();
NodeEditorWindow.current.Repaint(); NodeEditorWindow.current.Repaint();
@ -33,18 +36,40 @@ namespace XNodeEditor
{ {
_selected = false; _selected = false;
Selection.objects = lastSelection; Selection.objects = lastSelection;
window.selectedReroutes = lastSelectionReroutes;
} }
} }
base.OnHeaderGUI(); base.OnHeaderGUI();
} }
private void GetChildren(XNode.GroupNode group, ref List<UnityEngine.Object> list) private void SelectChildren(XNode.GroupNode group, ref List<UnityEngine.Object> selectionList)
{ {
var groupRect = new Rect(group.position, new Vector2(GetWidth(), GetHeight()));
foreach (var child in group.children) foreach (var child in group.children)
{ {
if (list.Contains(child)) continue; if (selectionList.Contains(child)) continue;
list.Add(child); selectionList.Add(child);
if (child is XNode.GroupNode _group) GetChildren(_group, ref list); var pc = child.Ports.Count();
for (int p = 0; p < pc; p++)
{
var port = child.Ports.ElementAt(p);
for (int i = 0; i < port.ConnectionCount; i++)
{
var connectionIndex = i;
if (port.direction == NodePort.IO.Input)
{
var newPort = port.GetConnection(i);
connectionIndex = newPort.GetConnectionIndex(port);
port = newPort;
}
var reroutes = port.GetReroutePoints(connectionIndex);
for (int j = 0; j < reroutes.Count; j++)
{
if (groupRect.Contains(reroutes[j])) window.selectedReroutes.Add(new RerouteReference(port, connectionIndex, j));
}
}
}
if (child is XNode.GroupNode _group) SelectChildren(_group, ref selectionList);
} }
} }
@ -81,8 +106,7 @@ namespace XNodeEditor
node.children.Min(x => x.position.x) - padding.x, node.children.Min(x => x.position.x) - padding.x,
node.children.Min(x => x.position.y) - padding.y node.children.Min(x => x.position.y) - padding.y
); );
Debug.Log(GetSize(node.children.FirstOrDefault())); GUILayout.Label(GUIContent.none);
GUILayout.Label("");
} }
public override Color GetTint() public override Color GetTint()

View File

@ -514,7 +514,7 @@ namespace XNodeEditor {
{ {
lastRect = GUILayoutUtility.GetLastRect(); lastRect = GUILayoutUtility.GetLastRect();
} }
float remainingSpace = height - lastRect.yMax - 17; float remainingSpace = height - lastRect.height - EditorGUIUtility.singleLineHeight;
GUILayout.Space(Mathf.Max(0,remainingSpace)); GUILayout.Space(Mathf.Max(0,remainingSpace));
} }

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace XNode namespace XNode
{ {
[NodeWidth(208), NodeHeight(176)] [NodeWidth(208), NodeHeight(208)]
public class GroupNode : Node public class GroupNode : Node
{ {
public Color color = new Color(1.0F,1.0F,1.0F,1.0F); public Color color = new Color(1.0F,1.0F,1.0F,1.0F);