From 90c362179575564d91b930bbd202ac52e1959a02 Mon Sep 17 00:00:00 2001 From: Thor Kramer Brigsted Date: Thu, 2 Nov 2017 17:37:11 +0100 Subject: [PATCH] Moved NodeEditor.[CustomNodeEditor].contextMenuName to Node.[CreateNodeMenu].menuName --- Example/Nodes/Editor/DisplayValueEditor.cs | 2 +- Scripts/Editor/NodeEditor.cs | 5 +---- Scripts/Editor/NodeEditorGUI.cs | 7 +++---- Scripts/Node.cs | 10 ++++++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Example/Nodes/Editor/DisplayValueEditor.cs b/Example/Nodes/Editor/DisplayValueEditor.cs index 4d37bc2..b928d3b 100644 --- a/Example/Nodes/Editor/DisplayValueEditor.cs +++ b/Example/Nodes/Editor/DisplayValueEditor.cs @@ -4,7 +4,7 @@ using UnityEditor; using UnityEngine; namespace BasicNodes { - [CustomNodeEditor(typeof(DisplayValue), "BasicNodes/DisplayValue")] + [CustomNodeEditor(typeof(DisplayValue))] public class DisplayValueEditor : NodeEditor { protected override void OnBodyGUI() { diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 1ede86b..990b22b 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -50,13 +50,10 @@ public class NodeEditor { public class CustomNodeEditorAttribute : Attribute { public Type inspectedType { get { return _inspectedType; } } private Type _inspectedType; - public string contextMenuName { get { return _contextMenuName; } } - private string _contextMenuName; /// Tells a NodeEditor which Node type it is an editor for /// Type that this editor can edit /// Path to the node - public CustomNodeEditorAttribute(Type inspectedType, string contextMenuName) { + public CustomNodeEditorAttribute(Type inspectedType) { _inspectedType = inspectedType; - _contextMenuName = contextMenuName; } } \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 0ba190d..879c95c 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -81,12 +81,11 @@ public partial class NodeEditorWindow { } else { for (int i = 0; i < nodeTypes.Length; i++) { Type type = nodeTypes[i]; - Type editorType = GetNodeEditor(type).GetType(); string name = nodeTypes[i].ToString().Replace('.', '/'); - CustomNodeEditorAttribute attrib; - if (NodeEditorUtilities.GetAttrib(editorType, out attrib)) { - name = attrib.contextMenuName; + Node.CreateNodeMenuAttribute attrib; + if (NodeEditorUtilities.GetAttrib(type, out attrib)) { + name = attrib.menuName; } contextMenu.AddItem(new GUIContent(name), false, () => { CreateNode(type, pos); diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 6df05cd..eab0c09 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -163,6 +163,16 @@ public abstract class Node : ScriptableObject { public OutputAttribute() { } } + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class CreateNodeMenuAttribute : Attribute { + public string menuName; + /// Manually supply node class with a context menu path + /// Path to this node in the context menu + public CreateNodeMenuAttribute(string menuName) { + this.menuName = menuName; + } + } + [Serializable] private class NodePortDictionary : Dictionary, ISerializationCallbackReceiver { [SerializeField] private List keys = new List(); [SerializeField] private List values = new List();