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

Moved NodeEditor.[CustomNodeEditor].contextMenuName to Node.[CreateNodeMenu].menuName

This commit is contained in:
Thor Kramer Brigsted 2017-11-02 17:37:11 +01:00
parent b70ba44c23
commit 90c3621795
4 changed files with 15 additions and 9 deletions

View File

@ -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() {

View File

@ -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;
/// <summary> Tells a NodeEditor which Node type it is an editor for </summary>
/// <param name="inspectedType">Type that this editor can edit</param>
/// <param name="contextMenuName">Path to the node</param>
public CustomNodeEditorAttribute(Type inspectedType, string contextMenuName) {
public CustomNodeEditorAttribute(Type inspectedType) {
_inspectedType = inspectedType;
_contextMenuName = contextMenuName;
}
}

View File

@ -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);

View File

@ -163,6 +163,16 @@ public abstract class Node : ScriptableObject {
public OutputAttribute() { }
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class CreateNodeMenuAttribute : Attribute {
public string menuName;
/// <summary> Manually supply node class with a context menu path </summary>
/// <param name="menuName"> Path to this node in the context menu </param>
public CreateNodeMenuAttribute(string menuName) {
this.menuName = menuName;
}
}
[Serializable] private class NodePortDictionary : Dictionary<string, NodePort>, ISerializationCallbackReceiver {
[SerializeField] private List<string> keys = new List<string>();
[SerializeField] private List<NodePort> values = new List<NodePort>();