1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 17:26:02 +08:00

Improved reroute point size, rendering, and enabled deletion of selected points

This commit is contained in:
Thor Brigsted 2018-04-12 09:27:50 +02:00
parent d721249b83
commit 9f09452b43
2 changed files with 22 additions and 7 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -303,6 +304,12 @@ namespace XNodeEditor {
/// <summary> Remove nodes in the graph in Selection.objects</summary> /// <summary> Remove nodes in the graph in Selection.objects</summary>
public void RemoveSelectedNodes() { public void RemoveSelectedNodes() {
// We need to delete reroutes starting at the highest point index to avoid shifting indices
selectedReroutes = selectedReroutes.OrderByDescending(x => x.pointIndex).ToList();
for (int i = 0; i < selectedReroutes.Count; i++) {
selectedReroutes[i].RemovePoint();
}
selectedReroutes.Clear();
foreach (UnityEngine.Object item in Selection.objects) { foreach (UnityEngine.Object item in Selection.objects) {
if (item is XNode.Node) { if (item is XNode.Node) {
XNode.Node node = item as XNode.Node; XNode.Node node = item as XNode.Node;

View File

@ -216,6 +216,7 @@ namespace XNodeEditor {
List<RerouteReference> selection = preBoxSelectionReroute != null ? new List<RerouteReference>(preBoxSelectionReroute) : new List<RerouteReference>(); List<RerouteReference> selection = preBoxSelectionReroute != null ? new List<RerouteReference>(preBoxSelectionReroute) : new List<RerouteReference>();
hoveredReroute = new RerouteReference(); hoveredReroute = new RerouteReference();
Color col = GUI.color;
foreach (XNode.Node node in graph.nodes) { foreach (XNode.Node node in graph.nodes) {
//If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset. //If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset.
if (node == null) continue; if (node == null) continue;
@ -249,21 +250,28 @@ namespace XNodeEditor {
// Loop through reroute points again and draw the points // Loop through reroute points again and draw the points
for (int i = 0; i < reroutePoints.Count; i++) { for (int i = 0; i < reroutePoints.Count; i++) {
RerouteReference rerouteRef = new RerouteReference(output, k, i);
// Draw reroute point at position // Draw reroute point at position
Rect rect = new Rect(reroutePoints[i], new Vector2(16, 16)); Rect rect = new Rect(reroutePoints[i], new Vector2(12, 12));
rect.position = new Vector2(rect.position.x - 8, rect.position.y - 8); rect.position = new Vector2(rect.position.x - 6, rect.position.y - 6);
rect = GridToWindowRect(rect); rect = GridToWindowRect(rect);
Color bgcol = new Color32(90, 97, 105, 255);;
if (selectedReroutes.Contains(new RerouteReference(output, k, i))) bgcol = Color.yellow;
NodeEditorGUILayout.DrawPortHandle(rect, bgcol, connectionColor);
if (rect.Overlaps(selectionBox)) selection.Add(new RerouteReference(output, k, i)); // Draw selected reroute points with an outline
if (rect.Contains(mousePos)) hoveredReroute = new RerouteReference(output, k, i); if (selectedReroutes.Contains(rerouteRef)) {
GUI.color = NodeEditorPreferences.GetSettings().highlightColor;
GUI.DrawTexture(rect, NodeEditorResources.dotOuter);
}
GUI.color = connectionColor;
GUI.DrawTexture(rect, NodeEditorResources.dot);
if (rect.Overlaps(selectionBox)) selection.Add(rerouteRef);
if (rect.Contains(mousePos)) hoveredReroute = rerouteRef;
} }
} }
} }
} }
GUI.color = col;
if (Event.current.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) selectedReroutes = selection; if (Event.current.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) selectedReroutes = selection;
} }