mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Removed resize corner icon.
This commit is contained in:
parent
b3465b269e
commit
f790b77575
@ -1,109 +1,186 @@
|
|||||||
using System.Collections;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using XNodeEditor.Internal;
|
||||||
|
|
||||||
namespace XNodeEditor.NodeGroups {
|
namespace XNodeEditor.NodeGroups
|
||||||
|
{
|
||||||
[CustomNodeEditor(typeof(NodeGroup))]
|
[CustomNodeEditor(typeof(NodeGroup))]
|
||||||
public class NodeGroupEditor : NodeEditor {
|
public class NodeGroupEditor : NodeEditor
|
||||||
private NodeGroup group { get { return _group != null ? _group : _group = target as NodeGroup; } }
|
{
|
||||||
|
private NodeGroup group => _group != null ? _group : _group = target as NodeGroup;
|
||||||
private NodeGroup _group;
|
private NodeGroup _group;
|
||||||
public static Texture2D corner { get { return _corner != null ? _corner : _corner = Resources.Load<Texture2D>("xnode_corner"); } }
|
|
||||||
private static Texture2D _corner;
|
|
||||||
private bool isDragging;
|
private bool isDragging;
|
||||||
private Vector2 size;
|
private Vector2 size;
|
||||||
|
|
||||||
public override void OnBodyGUI() {
|
public override void OnBodyGUI()
|
||||||
|
{
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
switch (e.type) {
|
switch (e.type)
|
||||||
|
{
|
||||||
case EventType.MouseDrag:
|
case EventType.MouseDrag:
|
||||||
if (isDragging) {
|
if (isDragging)
|
||||||
|
{
|
||||||
group.width = Mathf.Max(200, (int)e.mousePosition.x + 16);
|
group.width = Mathf.Max(200, (int)e.mousePosition.x + 16);
|
||||||
group.height = Mathf.Max(100, (int)e.mousePosition.y - 34);
|
group.height = Mathf.Max(100, (int)e.mousePosition.y - 34);
|
||||||
NodeEditorWindow.current.Repaint();
|
NodeEditorWindow.current.Repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EventType.MouseDown:
|
case EventType.MouseDown:
|
||||||
// Ignore everything except left clicks
|
// Ignore everything except left clicks
|
||||||
if (e.button != 0) return;
|
if (e.button != 0)
|
||||||
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size)) {
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size))
|
||||||
|
{
|
||||||
// Mouse position checking is in node local space
|
// Mouse position checking is in node local space
|
||||||
Rect lowerRight = new Rect(size.x - 34, size.y - 34, 30, 30);
|
Rect lowerRight = new Rect(size.x - 34, size.y - 34, 30, 30);
|
||||||
if (lowerRight.Contains(e.mousePosition)) {
|
if (lowerRight.Contains(e.mousePosition))
|
||||||
|
{
|
||||||
isDragging = true;
|
isDragging = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EventType.MouseUp:
|
case EventType.MouseUp:
|
||||||
isDragging = false;
|
isDragging = false;
|
||||||
// Select nodes inside the group
|
// Select nodes inside the group
|
||||||
if (Selection.Contains(target)) {
|
if (Selection.Contains(target))
|
||||||
List<Object> selection = Selection.objects.ToList();
|
{
|
||||||
|
var selection = Selection.objects.ToList();
|
||||||
// Select Nodes
|
// Select Nodes
|
||||||
selection.AddRange(group.GetNodes());
|
selection.AddRange(group.GetNodes());
|
||||||
// Select Reroutes
|
// Select Reroutes
|
||||||
foreach (Node node in target.graph.nodes) {
|
foreach (Node node in target.graph.nodes)
|
||||||
|
{
|
||||||
if (node != null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
foreach (NodePort port in node.Ports) {
|
foreach (NodePort port in node.Ports)
|
||||||
for (int i = 0; i < port.ConnectionCount; i++) {
|
{
|
||||||
List<Vector2> reroutes = port.GetReroutePoints(i);
|
for (int i = 0; i < port.ConnectionCount; i++)
|
||||||
for (int k = 0; k < reroutes.Count; k++) {
|
{
|
||||||
|
var reroutes = port.GetReroutePoints(i);
|
||||||
|
for (int k = 0; k < reroutes.Count; k++)
|
||||||
|
{
|
||||||
Vector2 p = reroutes[k];
|
Vector2 p = reroutes[k];
|
||||||
if (p.x < group.position.x) continue;
|
if (p.x < group.position.x)
|
||||||
if (p.y < group.position.y) continue;
|
{
|
||||||
if (p.x > group.position.x + group.width) continue;
|
continue;
|
||||||
if (p.y > group.position.y + group.height + 30) continue;
|
}
|
||||||
if (NodeEditorWindow.current.selectedReroutes.Any(x => x.port == port && x.connectionIndex == i && x.pointIndex == k)) continue;
|
|
||||||
|
if (p.y < group.position.y)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.x > group.position.x + group.width)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.y > group.position.y + group.height + 30)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NodeEditorWindow.current.selectedReroutes.Any(x =>
|
||||||
|
x.port == port && x.connectionIndex == i && x.pointIndex == k))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
NodeEditorWindow.current.selectedReroutes.Add(
|
NodeEditorWindow.current.selectedReroutes.Add(
|
||||||
new Internal.RerouteReference(port, i, k)
|
new RerouteReference(port, i, k)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Selection.objects = selection.Distinct().ToArray();
|
Selection.objects = selection.Distinct().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EventType.Repaint:
|
case EventType.Repaint:
|
||||||
// Move to bottom
|
// Move to bottom
|
||||||
if (target.graph.nodes.IndexOf(target) != 0) {
|
if (target.graph.nodes.IndexOf(target) != 0)
|
||||||
|
{
|
||||||
target.graph.nodes.Remove(target);
|
target.graph.nodes.Remove(target);
|
||||||
target.graph.nodes.Insert(0, target);
|
target.graph.nodes.Insert(0, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add scale cursors
|
// Add scale cursors
|
||||||
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size)) {
|
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size))
|
||||||
|
{
|
||||||
Rect lowerRight = new Rect(target.position, new Vector2(30, 30));
|
Rect lowerRight = new Rect(target.position, new Vector2(30, 30));
|
||||||
lowerRight.y += size.y - 34;
|
lowerRight.y += size.y - 34;
|
||||||
lowerRight.x += size.x - 34;
|
lowerRight.x += size.x - 34;
|
||||||
lowerRight = NodeEditorWindow.current.GridToWindowRect(lowerRight);
|
lowerRight = NodeEditorWindow.current.GridToWindowRect(lowerRight);
|
||||||
NodeEditorWindow.current.onLateGUI += () => AddMouseRect(lowerRight);
|
NodeEditorWindow.current.onLateGUI += () => AddMouseRect(lowerRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Control height of node
|
// Control height of node
|
||||||
GUILayout.Space(group.height);
|
GUILayout.Space(group.height);
|
||||||
|
|
||||||
GUI.DrawTexture(new Rect(group.width - 34, group.height + 16, 24, 24), corner);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetWidth() {
|
public override int GetWidth()
|
||||||
|
{
|
||||||
return group.width;
|
return group.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Color GetTint() {
|
public override Color GetTint()
|
||||||
|
{
|
||||||
return group.color;
|
return group.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddMouseRect(Rect rect) {
|
public static void AddMouseRect(Rect rect)
|
||||||
|
{
|
||||||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeUpLeft);
|
EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeUpLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void AddContextMenuItems(GenericMenu menu)
|
||||||
|
{
|
||||||
|
bool canRemove = true;
|
||||||
|
|
||||||
|
menu.AddItem(new GUIContent("Rename Group"), false, RenameNodeGroup);
|
||||||
|
|
||||||
|
// Add actions to any number of selected nodes
|
||||||
|
menu.AddItem(new GUIContent("Copy"), false, NodeEditorWindow.current.CopySelectedNodes);
|
||||||
|
menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes);
|
||||||
|
|
||||||
|
if (canRemove)
|
||||||
|
{
|
||||||
|
menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menu.AddItem(new GUIContent("Remove"), false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenameNodeGroup()
|
||||||
|
{
|
||||||
|
var nodeGroups = Selection.objects.ToList().Where(x => x is NodeGroup).ToList();
|
||||||
|
if (nodeGroups.Count == 1)
|
||||||
|
{
|
||||||
|
NodeGroup group = nodeGroups[0] as NodeGroup;
|
||||||
|
Vector2 size;
|
||||||
|
if (NodeEditorWindow.current.nodeSizes.TryGetValue(group, out size))
|
||||||
|
{
|
||||||
|
RenamePopup.Show(group, size.x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RenamePopup.Show(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11
Scripts/Editor/NodeGroupEditor.cs.meta
Normal file
11
Scripts/Editor/NodeGroupEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e8f0cf758226756468d74e8705be5d9d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
11
Scripts/NodeGroup.cs.meta
Normal file
11
Scripts/NodeGroup.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5787b2461d90cae4b924a89398060381
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user