From 788b8d8a0b7aad02e8f4c480aff597b265ceebe3 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Mon, 12 Aug 2019 00:11:14 +0200 Subject: [PATCH] Automatically remove "Node" postfix from creation menu --- Scripts/Editor/NodeEditorUtilities.cs | 9 +++++++++ Scripts/Editor/NodeGraphEditor.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorUtilities.cs b/Scripts/Editor/NodeEditorUtilities.cs index c636309..bf92ba8 100644 --- a/Scripts/Editor/NodeEditorUtilities.cs +++ b/Scripts/Editor/NodeEditorUtilities.cs @@ -150,6 +150,15 @@ namespace XNodeEditor { return typeName; } + /// Returns the default creation path for the node type. + public static string NodeDefaultPath(Type type) { + string typePath = type.ToString().Replace('.', '/'); + // Automatically remove redundant 'Node' postfix + if (typePath.EndsWith("Node")) typePath = typePath.Substring(0, typePath.LastIndexOf("Node")); + typePath = UnityEditor.ObjectNames.NicifyVariableName(typePath); + return typePath; + } + /// Creates a new C# Class. [MenuItem("Assets/Create/xNode/Node C# Script", false, 89)] private static void CreateNode() { diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 110c506..a45d566 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -38,7 +38,7 @@ namespace XNodeEditor { if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path return attrib.menuName; else // Return generated path - return ObjectNames.NicifyVariableName(type.ToString().Replace('.', '/')); + return NodeEditorUtilities.NodeDefaultPath(type); } /// Add items for the context menu when right-clicking this node. Override to add custom menu items.