using System; using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; namespace XNodeEditor { /// Base class to derive custom Node Graph editors from. Use this to override how graphs are drawn in the editor. [CustomNodeGraphEditor(typeof(XNode.NodeGraph))] public class NodeGraphEditor : XNodeInternal.NodeEditorBase { /// Custom node editors defined with [CustomNodeGraphEditor] [NonSerialized] private static Dictionary editors; public virtual Texture2D GetGridTexture() { return NodeEditorPreferences.gridTexture; } public virtual Texture2D GetSecondaryGridTexture() { return NodeEditorPreferences.crossTexture; } /// Returns context menu path. Returns null if node is not available. 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.INodeEditorAttrib { private Type inspectedType; /// Tells a NodeEditor which Node type it is an editor for /// Type that this editor can edit /// Path to the node public CustomNodeGraphEditorAttribute(Type inspectedType) { this.inspectedType = inspectedType; } public Type GetInspectedType() { return inspectedType; } } } }