mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
52 lines
2.3 KiB
C#
52 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace XNodeEditor {
|
|
/// <summary> Base class to derive custom Node Graph editors from. Use this to override how graphs are drawn in the editor. </summary>
|
|
[CustomNodeGraphEditor(typeof(XNode.NodeGraph))]
|
|
public class NodeGraphEditor : XNodeInternal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, XNode.NodeGraph> {
|
|
/// <summary> Custom node editors defined with [CustomNodeGraphEditor] </summary>
|
|
[NonSerialized] private static Dictionary<Type, NodeGraphEditor> editors;
|
|
|
|
public virtual Texture2D GetGridTexture() {
|
|
return NodeEditorPreferences.gridTexture;
|
|
}
|
|
|
|
public virtual Texture2D GetSecondaryGridTexture() {
|
|
return NodeEditorPreferences.crossTexture;
|
|
}
|
|
|
|
/// <summary> Returns context menu path. Returns null if node is not available. </summary>
|
|
public virtual string GetNodePath(Type type) {
|
|
//Check if type has the CreateNodeMenuAttribute
|
|
XNode.Node.CreateNodeMenuAttribute attrib;
|
|
if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path
|
|
return attrib.menuName;
|
|
else // Return generated path
|
|
return ObjectNames.NicifyVariableName(type.ToString().Replace('.', '/'));
|
|
}
|
|
|
|
public virtual Color GetTypeColor(Type type) {
|
|
return NodeEditorPreferences.GetTypeColor(type);
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Class)]
|
|
public class CustomNodeGraphEditorAttribute : Attribute,
|
|
XNodeInternal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, XNode.NodeGraph>.INodeEditorAttrib {
|
|
private Type inspectedType;
|
|
/// <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 CustomNodeGraphEditorAttribute(Type inspectedType) {
|
|
this.inspectedType = inspectedType;
|
|
}
|
|
|
|
public Type GetInspectedType() {
|
|
return inspectedType;
|
|
}
|
|
}
|
|
}
|
|
} |