diff --git a/Example/ExampleNodeGraph.cs b/Example/ExampleNodeGraph.cs index 8b09ece..c9a7fa1 100644 --- a/Example/ExampleNodeGraph.cs +++ b/Example/ExampleNodeGraph.cs @@ -4,5 +4,5 @@ using XNode; /// Defines an example nodegraph. [Serializable, CreateAssetMenu(fileName = "ExampleNodeGraph", menuName = "Node Graph/Example")] -public class ExampleNodeGraph : NodeGraph { +public class ExampleNodeGraph : XNode.NodeGraph { } diff --git a/Example/Nodes/DisplayValue.cs b/Example/Nodes/DisplayValue.cs index f9b55cb..5340a99 100644 --- a/Example/Nodes/DisplayValue.cs +++ b/Example/Nodes/DisplayValue.cs @@ -1,13 +1,13 @@ using XNode; namespace BasicNodes { - public class DisplayValue : Node { + public class DisplayValue : XNode.Node { protected override void Init() { base.Init(); if (!HasPort("input")) AddInstanceInput(typeof(object), "input"); } - public override object GetValue(NodePort port) { + public override object GetValue(XNode.NodePort port) { return GetInputValue("input"); } } diff --git a/Example/Nodes/MathNode.cs b/Example/Nodes/MathNode.cs index b94bbca..bba473e 100644 --- a/Example/Nodes/MathNode.cs +++ b/Example/Nodes/MathNode.cs @@ -2,7 +2,7 @@ namespace BasicNodes { [System.Serializable] - public class MathNode : Node { + public class MathNode : XNode.Node { // Adding [Input] or [Output] is all you need to do to register a field as a valid port on your node [Input] public float a; [Input] public float b; @@ -14,7 +14,7 @@ namespace BasicNodes { public enum MathType { Add, Subtract, Multiply, Divide } // GetValue should be overridden to return a value for any specified output port - public override object GetValue(NodePort port) { + public override object GetValue(XNode.NodePort port) { // Get new a and b values from input connections. Fallback to field values if input is not connected float a = GetInputValue("a", this.a); diff --git a/Example/Nodes/Vector.cs b/Example/Nodes/Vector.cs index 4c729fb..7141d2e 100644 --- a/Example/Nodes/Vector.cs +++ b/Example/Nodes/Vector.cs @@ -2,11 +2,11 @@ using XNode; namespace BasicNodes { - public class Vector : Node { + public class Vector : XNode.Node { [Input] public float x, y, z; [Output] public Vector3 vector; - public override object GetValue(NodePort port) { + public override object GetValue(XNode.NodePort port) { vector.x = GetInputValue("x", this.x); vector.y = GetInputValue("y", this.y); vector.z = GetInputValue("z", this.z); diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 5d093a7..7550124 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -8,12 +8,12 @@ using XNode; namespace XNodeEditor { /// Base class to derive custom Node editors from. Use this to create your own custom inspectors and editors for your nodes. - [CustomNodeEditor(typeof(Node))] - public class NodeEditor : XNodeInternal.NodeEditorBase { + [CustomNodeEditor(typeof(XNode.Node))] + public class NodeEditor : XNodeInternal.NodeEditorBase { /// Fires every whenever a node was modified through the editor - public static Action onUpdateNode; - public static Dictionary portPositions; + public static Action onUpdateNode; + public static Dictionary portPositions; /// Draws the node GUI. /// Port handle positions need to be returned to the NodeEditorWindow @@ -31,7 +31,7 @@ namespace XNodeEditor { /// Draws standard field editors for all public fields public virtual void OnBodyGUI() { string[] excludes = { "m_Script", "graph", "position", "ports" }; - portPositions = new Dictionary(); + portPositions = new Dictionary(); SerializedProperty iterator = serializedObject.GetIterator(); bool enterChildren = true; diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index f83a731..8483929 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -15,13 +15,13 @@ namespace XNodeEditor { private bool IsHoveringNode { get { return hoveredNode != null; } } private bool HasSelectedNode { get { return selectedNode != null; } } - private Node hoveredNode = null; + private XNode.Node hoveredNode = null; - [NonSerialized] private Node selectedNode = null; - [NonSerialized] private Node draggedNode = null; - [NonSerialized] private NodePort hoveredPort = null; - [NonSerialized] private NodePort draggedOutput = null; - [NonSerialized] private NodePort draggedOutputTarget = null; + [NonSerialized] private XNode.Node selectedNode = null; + [NonSerialized] private XNode.Node draggedNode = null; + [NonSerialized] private XNode.NodePort hoveredPort = null; + [NonSerialized] private XNode.NodePort draggedOutput = null; + [NonSerialized] private XNode.NodePort draggedOutputTarget = null; private Rect nodeRects; @@ -69,8 +69,8 @@ namespace XNodeEditor { } else { hoveredPort.VerifyConnections(); if (hoveredPort.IsConnected) { - Node node = hoveredPort.node; - NodePort output = hoveredPort.Connection; + XNode.Node node = hoveredPort.node; + XNode.NodePort output = hoveredPort.Connection; hoveredPort.Disconnect(output); draggedOutput = output; draggedOutputTarget = hoveredPort; @@ -89,7 +89,7 @@ namespace XNodeEditor { if (IsDraggingPort) { //If connection is valid, save it if (draggedOutputTarget != null) { - Node node = draggedOutputTarget.node; + XNode.Node node = draggedOutputTarget.node; if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget); if (NodeEditor.onUpdateNode != null) NodeEditor.onUpdateNode(node); EditorUtility.SetDirty(graph); @@ -127,7 +127,7 @@ namespace XNodeEditor { } public void CreateNode(Type type, Vector2 position) { - Node node = graph.AddNode(type); + XNode.Node node = graph.AddNode(type); node.position = position; Repaint(); } @@ -144,7 +144,7 @@ namespace XNodeEditor { } } - bool IsHoveringTitle(Node node) { + bool IsHoveringTitle(XNode.Node node) { Vector2 mousePos = Event.current.mousePosition; //Get node position Vector2 nodePos = GridToWindowPosition(node.position); diff --git a/Scripts/Editor/NodeEditorAssetModProcessor.cs b/Scripts/Editor/NodeEditorAssetModProcessor.cs index aa50f02..53c66e1 100644 --- a/Scripts/Editor/NodeEditorAssetModProcessor.cs +++ b/Scripts/Editor/NodeEditorAssetModProcessor.cs @@ -12,7 +12,7 @@ namespace XNodeEditor { UnityEditor.MonoScript script = obj as UnityEditor.MonoScript; System.Type scriptType = script.GetClass(); - if (scriptType != typeof(Node) && !scriptType.IsSubclassOf(typeof(Node))) return AssetDeleteResult.DidNotDelete; + if (scriptType != typeof(XNode.Node) && !scriptType.IsSubclassOf(typeof(XNode.Node))) return AssetDeleteResult.DidNotDelete; //Find ScriptableObjects using this script string[] guids = AssetDatabase.FindAssets("t:" + scriptType); @@ -20,7 +20,7 @@ namespace XNodeEditor { string assetpath = AssetDatabase.GUIDToAssetPath(guids[i]); Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetpath); for (int k = 0; k < objs.Length; k++) { - Node node = objs[k] as Node; + XNode.Node node = objs[k] as XNode.Node; if (node.GetType() == scriptType) { if (node != null && node.graph != null) { Debug.LogWarning(node.name + " of " + node.graph + " depended on deleted script and has been removed automatically.", node.graph); diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index c135401..2887b62 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -76,7 +76,7 @@ namespace XNodeEditor { } /// Show right-click context menu for a node - public void ShowNodeContextMenu(Node node) { + public void ShowNodeContextMenu(XNode.Node node) { GenericMenu contextMenu = new GenericMenu(); contextMenu.AddItem(new GUIContent("Move To Top"), false, () => { int index; @@ -86,7 +86,7 @@ namespace XNodeEditor { } }); contextMenu.AddItem(new GUIContent("Duplicate"), false, () => { - Node n = graph.CopyNode(node); + XNode.Node n = graph.CopyNode(node); n.position = node.position + new Vector2(30, 30); }); contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node)); @@ -145,17 +145,17 @@ namespace XNodeEditor { /// Draws all connections public void DrawConnections() { - foreach (Node node in graph.nodes) { + foreach (XNode.Node node in graph.nodes) { //If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset. if (node == null) continue; - foreach (NodePort output in node.Outputs) { + foreach (XNode.NodePort output in node.Outputs) { //Needs cleanup. Null checks are ugly if (!portConnectionPoints.ContainsKey(output)) continue; Vector2 from = _portConnectionPoints[output].center; for (int k = 0; k < output.ConnectionCount; k++) { - NodePort input = output.GetConnection(k); + XNode.NodePort input = output.GetConnection(k); if (input == null) continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return. if (!input.IsConnectedTo(output)) input.Connect(output); if (!_portConnectionPoints.ContainsKey(input)) continue; @@ -196,10 +196,10 @@ namespace XNodeEditor { for (int n = 0; n < graph.nodes.Count; n++) { while (graph.nodes[n] == null) graph.nodes.RemoveAt(n); if (n >= graph.nodes.Count) return; - Node node = graph.nodes[n]; + XNode.Node node = graph.nodes[n]; NodeEditor nodeEditor = NodeEditor.GetEditor(node); - NodeEditor.portPositions = new Dictionary(); + NodeEditor.portPositions = new Dictionary(); //Get node position Vector2 nodePos = GridToWindowPositionNoClipped(node.position); @@ -244,14 +244,14 @@ namespace XNodeEditor { //Check if we are hovering any of this nodes ports //Check input ports - foreach (NodePort input in node.Inputs) { + foreach (XNode.NodePort input in node.Inputs) { //Check if port rect is available if (!portConnectionPoints.ContainsKey(input)) continue; Rect r = GridToWindowRect(portConnectionPoints[input]); if (r.Contains(mousePos)) hoveredPort = input; } //Check all output ports - foreach (NodePort output in node.Outputs) { + foreach (XNode.NodePort output in node.Outputs) { //Check if port rect is available if (!portConnectionPoints.ContainsKey(output)) continue; Rect r = GridToWindowRect(portConnectionPoints[output]); diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index e01e50b..1a0f379 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -16,18 +16,18 @@ namespace XNodeEditor { /// Make a field for a serialized property. Automatically displays relevant node port. public static void PropertyField(SerializedProperty property, GUIContent label, bool includeChildren = true, params GUILayoutOption[] options) { if (property == null) throw new NullReferenceException(); - Node node = property.serializedObject.targetObject as Node; - NodePort port = node.GetPort(property.name); + XNode.Node node = property.serializedObject.targetObject as XNode.Node; + XNode.NodePort port = node.GetPort(property.name); PropertyField(property, label, port, includeChildren); } /// Make a field for a serialized property. Manual node port override. - public static void PropertyField(SerializedProperty property, NodePort port, bool includeChildren = true, params GUILayoutOption[] options) { + public static void PropertyField(SerializedProperty property, XNode.NodePort port, bool includeChildren = true, params GUILayoutOption[] options) { PropertyField(property, null, port, includeChildren, options); } /// Make a field for a serialized property. Manual node port override. - public static void PropertyField(SerializedProperty property, GUIContent label, NodePort port, bool includeChildren = true, params GUILayoutOption[] options) { + public static void PropertyField(SerializedProperty property, GUIContent label, XNode.NodePort port, bool includeChildren = true, params GUILayoutOption[] options) { if (property == null) throw new NullReferenceException(); // If property is not a port, display a regular property field @@ -36,24 +36,24 @@ namespace XNodeEditor { Rect rect = new Rect(); // If property is an input, display a regular property field and put a port handle on the left side - if (port.direction == NodePort.IO.Input) { + if (port.direction == XNode.NodePort.IO.Input) { // Get data from [Input] attribute - Node.ShowBackingValue showBacking = Node.ShowBackingValue.Unconnected; - Node.InputAttribute inputAttribute; + XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected; + XNode.Node.InputAttribute inputAttribute; if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out inputAttribute)) showBacking = inputAttribute.backingValue; switch (showBacking) { - case Node.ShowBackingValue.Unconnected: + case XNode.Node.ShowBackingValue.Unconnected: // Display a label if port is connected if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); // Display an editable property field if port is not connected else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); break; - case Node.ShowBackingValue.Never: + case XNode.Node.ShowBackingValue.Never: // Display a label EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); break; - case Node.ShowBackingValue.Always: + case XNode.Node.ShowBackingValue.Always: // Display an editable property field EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); break; @@ -62,24 +62,24 @@ namespace XNodeEditor { rect = GUILayoutUtility.GetLastRect(); rect.position = rect.position - new Vector2(16, 0); // If property is an output, display a text label and put a port handle on the right side - } else if (port.direction == NodePort.IO.Output) { + } else if (port.direction == XNode.NodePort.IO.Output) { // Get data from [Output] attribute - Node.ShowBackingValue showBacking = Node.ShowBackingValue.Unconnected; - Node.OutputAttribute outputAttribute; + XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected; + XNode.Node.OutputAttribute outputAttribute; if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out outputAttribute)) showBacking = outputAttribute.backingValue; switch (showBacking) { - case Node.ShowBackingValue.Unconnected: + case XNode.Node.ShowBackingValue.Unconnected: // Display a label if port is connected if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30)); // Display an editable property field if port is not connected else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); break; - case Node.ShowBackingValue.Never: + case XNode.Node.ShowBackingValue.Never: // Display a label EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30)); break; - case Node.ShowBackingValue.Always: + case XNode.Node.ShowBackingValue.Always: // Display an editable property field EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); break; @@ -104,18 +104,18 @@ namespace XNodeEditor { } /// Make a simple port field. - public static void PortField(NodePort port, params GUILayoutOption[] options) { + public static void PortField(XNode.NodePort port, params GUILayoutOption[] options) { PortField(null, port, options); } /// Make a simple port field. - public static void PortField(GUIContent label, NodePort port, params GUILayoutOption[] options) { + public static void PortField(GUIContent label, XNode.NodePort port, params GUILayoutOption[] options) { if (port == null) return; if (label == null) EditorGUILayout.LabelField(ObjectNames.NicifyVariableName(port.fieldName), options); else EditorGUILayout.LabelField(label, options); Rect rect = GUILayoutUtility.GetLastRect(); - if (port.direction == NodePort.IO.Input) rect.position = rect.position - new Vector2(16, 0); - else if (port.direction == NodePort.IO.Output) rect.position = rect.position + new Vector2(rect.width, 0); + if (port.direction == XNode.NodePort.IO.Input) rect.position = rect.position - new Vector2(16, 0); + else if (port.direction == XNode.NodePort.IO.Output) rect.position = rect.position + new Vector2(rect.width, 0); rect.size = new Vector2(16, 16); Color backgroundColor = new Color32(90, 97, 105, 255); diff --git a/Scripts/Editor/NodeEditorReflection.cs b/Scripts/Editor/NodeEditorReflection.cs index 319bfe5..1c30bf5 100644 --- a/Scripts/Editor/NodeEditorReflection.cs +++ b/Scripts/Editor/NodeEditorReflection.cs @@ -19,15 +19,15 @@ namespace XNodeEditor { public static Type[] GetNodeTypes() { //Get all classes deriving from Node via reflection - return GetDerivedTypes(typeof(Node)); + return GetDerivedTypes(typeof(XNode.Node)); } public static Dictionary GetNodeTint() { Dictionary tints = new Dictionary(); for (int i = 0; i < nodeTypes.Length; i++) { - var attribs = nodeTypes[i].GetCustomAttributes(typeof(Node.NodeTint), true); + var attribs = nodeTypes[i].GetCustomAttributes(typeof(XNode.Node.NodeTint), true); if (attribs == null || attribs.Length == 0) continue; - Node.NodeTint attrib = attribs[0] as Node.NodeTint; + XNode.Node.NodeTint attrib = attribs[0] as XNode.Node.NodeTint; tints.Add(nodeTypes[i], attrib.color); } return tints; diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index 1c60e1a..fc5ed7b 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -10,11 +10,11 @@ namespace XNodeEditor { public static NodeEditorWindow current; /// Stores node positions for all nodePorts. - public Dictionary portConnectionPoints { get { return _portConnectionPoints; } } - private Dictionary _portConnectionPoints = new Dictionary(); - public Dictionary nodeWidths { get { return _nodeWidths; } } - private Dictionary _nodeWidths = new Dictionary(); - public NodeGraph graph; + public Dictionary portConnectionPoints { get { return _portConnectionPoints; } } + private Dictionary _portConnectionPoints = new Dictionary(); + public Dictionary nodeWidths { get { return _nodeWidths; } } + private Dictionary _nodeWidths = new Dictionary(); + public XNode.NodeGraph graph; public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } } private Vector2 _panOffset; public float zoom { get { return _zoom; } set { _zoom = Mathf.Clamp(value, 1f, 5f); Repaint(); } } @@ -46,7 +46,7 @@ namespace XNodeEditor { string path = EditorUtility.SaveFilePanelInProject("Save NodeGraph", "NewNodeGraph", "asset", ""); if (string.IsNullOrEmpty(path)) return; else { - NodeGraph existingGraph = AssetDatabase.LoadAssetAtPath(path); + XNode.NodeGraph existingGraph = AssetDatabase.LoadAssetAtPath(path); if (existingGraph != null) AssetDatabase.DeleteAsset(path); AssetDatabase.CreateAsset(graph, path); EditorUtility.SetDirty(graph); @@ -78,13 +78,13 @@ namespace XNodeEditor { return new Vector2(xOffset, yOffset); } - public void SelectNode(Node node) { + public void SelectNode(XNode.Node node) { selectedNode = node; } [OnOpenAsset(0)] public static bool OnOpen(int instanceID, int line) { - NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph; + XNode.NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as XNode.NodeGraph; if (nodeGraph != null) { NodeEditorWindow w = Init(); w.graph = nodeGraph; diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 2205e84..9c3d1e3 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -7,8 +7,8 @@ using XNode; namespace XNodeEditor { /// Base class to derive custom Node Graph editors from. Use this to override how graphs are drawn in the editor. - [CustomNodeGraphEditor(typeof(NodeGraph))] - public class NodeGraphEditor : XNodeInternal.NodeEditorBase { + [CustomNodeGraphEditor(typeof(XNode.NodeGraph))] + public class NodeGraphEditor : XNodeInternal.NodeEditorBase { /// Custom node editors defined with [CustomNodeGraphEditor] [NonSerialized] private static Dictionary editors; @@ -23,7 +23,7 @@ namespace XNodeEditor { /// Returns context menu path. Returns null if node is not available. public virtual string GetNodePath(Type type) { //Check if type has the CreateNodeMenuAttribute - Node.CreateNodeMenuAttribute attrib; + XNode.Node.CreateNodeMenuAttribute attrib; if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path return attrib.menuName; else // Return generated path