diff --git a/Editor/GroupNodeEditor.cs b/Editor/GroupNodeEditor.cs
index 5ccbaf7..476ae3c 100644
--- a/Editor/GroupNodeEditor.cs
+++ b/Editor/GroupNodeEditor.cs
@@ -78,6 +78,11 @@ namespace XNodeEditor
var e = Event.current;
var node = target as XNode.GroupNode;
+ for (int i = node.children.Count - 1; i >= 0; i--)
+ {
+ if (node.children[i] == null) node.children.RemoveAt(i);
+ }
+
var nodes = node.graph.nodes;
if (e.type == EventType.Repaint)
{
diff --git a/Editor/NodeEditor.cs b/Editor/NodeEditor.cs
index 1caf7a7..4ca9ad2 100644
--- a/Editor/NodeEditor.cs
+++ b/Editor/NodeEditor.cs
@@ -31,11 +31,9 @@ namespace XNodeEditor {
{
var content = new GUIContent(target.name);
var type = target.GetType();
- if (type.TryGetAttributeHeader(out GUIContent attrContent))
+ if (type.TryGetAttributeHeader(out GUIContent attrContent) && content.text == NodeEditorUtilities.NodeDefaultName(type))
{
- if (content.text != NodeEditorUtilities.NodeDefaultName(type))
- attrContent.text = content.text;
- content = attrContent;
+ content = new GUIContent(attrContent);
}
GUILayout.Label(content, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30));
}
diff --git a/Editor/NodeEditorAction.cs b/Editor/NodeEditorAction.cs
index 265a42f..8269ca6 100644
--- a/Editor/NodeEditorAction.cs
+++ b/Editor/NodeEditorAction.cs
@@ -415,16 +415,61 @@ namespace XNodeEditor {
}
}
+ public Node currentRenamingNode
+ {
+ get => _currentRename;
+ set
+ {
+ if (_currentRename == value) return;
+ _currentRename = value;
+ if (value != null)
+ {
+ _currentRenameString = value.name;
+ }
+ }
+ }
+ private Node _currentRename;
+ private const string renameControlName = "renameNodeInput";
+ private string _currentRenameString;
+
+ private void RenameGUI()
+ {
+ var node = currentRenamingNode;
+ if (node == null) return;
+ GUI.SetNextControlName(renameControlName);
+ var rect = GridToWindowRectNoClipped(
+ new Rect(node.position + new Vector2(16,9),
+ (nodeSizes.TryGetValue(node, out var size) ? size : new Vector2(180, EditorGUIUtility.singleLineHeight))
+ - new Vector2(32, 18)
+ ) {height = EditorGUIUtility.singleLineHeight});
+ _currentRenameString = GUI.TextField(rect, _currentRenameString);
+ EditorGUI.FocusTextInControl(renameControlName);
+ var e = Event.current;
+ if ((e.isKey && (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.Escape)) ||
+ (e.isMouse && e.type == EventType.MouseDown && !rect.Contains(e.mousePosition)))
+ {
+ var newName = (e.keyCode == KeyCode.Escape || _currentRenameString == null || _currentRenameString.Trim() == "") ?
+ NodeEditorUtilities.NodeDefaultName(node.GetType()) :
+ _currentRenameString;
+
+ node.name = newName;
+ NodeEditor.GetEditor(node, this).OnRename();
+
+ if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(node))) {
+ AssetDatabase.SetMainObject((node).graph, AssetDatabase.GetAssetPath(node));
+ AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(node));
+ }
+ currentRenamingNode = null;
+ EditorGUIUtility.editingTextField = false;
+ node.TriggerOnValidate();
+ }
+ }
/// Initiate a rename on the currently selected node
public void RenameSelectedNode() {
- if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
+ if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node)
+ {
XNode.Node node = Selection.activeObject as XNode.Node;
- Vector2 size;
- if (nodeSizes.TryGetValue(node, out size)) {
- RenamePopup.Show(Selection.activeObject, size.x);
- } else {
- RenamePopup.Show(Selection.activeObject);
- }
+ currentRenamingNode = node;
}
}
diff --git a/Editor/NodeEditorGUI.cs b/Editor/NodeEditorGUI.cs
index b8b4b6d..bfc179e 100644
--- a/Editor/NodeEditorGUI.cs
+++ b/Editor/NodeEditorGUI.cs
@@ -34,6 +34,7 @@ namespace XNodeEditor {
DrawNodes();
DrawSelectionBox();
DrawTooltip();
+ RenameGUI();
graphEditor.OnGUI();
// Run and reset onLateGUI
diff --git a/Editor/RenamePopup.cs b/Editor/RenamePopup.cs
deleted file mode 100644
index ca1ee15..0000000
--- a/Editor/RenamePopup.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using UnityEditor;
-using UnityEngine;
-
-namespace XNodeEditor {
- /// Utility for renaming assets
- public class RenamePopup : EditorWindow {
- private const string inputControlName = "nameInput";
-
- public static RenamePopup current { get; private set; }
- public Object target;
- public string input;
-
- private bool firstFrame = true;
-
- /// Show a rename popup for an asset at mouse position. Will trigger reimport of the asset on apply.
- public static RenamePopup Show(Object target, float width = 200) {
- RenamePopup window = EditorWindow.GetWindow(true, "Rename " + target.name, true);
- if (current != null) current.Close();
- current = window;
- window.target = target;
- window.input = target.name;
- window.minSize = new Vector2(100, 44);
- window.position = new Rect(0, 0, width, 44);
- window.UpdatePositionToMouse();
- return window;
- }
-
- private void UpdatePositionToMouse() {
- if (Event.current == null) return;
- Vector3 mousePoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
- Rect pos = position;
- pos.x = mousePoint.x - position.width * 0.5f;
- pos.y = mousePoint.y - 10;
- position = pos;
- }
-
- private void OnLostFocus() {
- // Make the popup close on lose focus
- Close();
- }
-
- private void OnGUI() {
- if (firstFrame) {
- UpdatePositionToMouse();
- firstFrame = false;
- }
- GUI.SetNextControlName(inputControlName);
- input = EditorGUILayout.TextField(input);
- EditorGUI.FocusTextInControl(inputControlName);
- Event e = Event.current;
- // If input is empty, revert name to default instead
- if (input == null || input.Trim() == "") {
- if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) {
- target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
- NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
- if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) {
- AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
- AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
- }
- Close();
- target.TriggerOnValidate();
- }
- }
- // Rename asset to input text
- else {
- if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
- target.name = input;
- NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
- if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) {
- AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
- AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
- }
- Close();
- target.TriggerOnValidate();
- }
- }
-
- if (e.isKey && e.keyCode == KeyCode.Escape) {
- Close();
- }
- }
-
- private void OnDestroy() {
- EditorGUIUtility.editingTextField = false;
- }
- }
-}
\ No newline at end of file
diff --git a/Editor/RenamePopup.cs.meta b/Editor/RenamePopup.cs.meta
deleted file mode 100644
index 5c40a02..0000000
--- a/Editor/RenamePopup.cs.meta
+++ /dev/null
@@ -1,13 +0,0 @@
-fileFormatVersion: 2
-guid: 4ef3ddc25518318469bce838980c64be
-timeCreated: 1552067957
-licenseType: Free
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant: