1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Simple refactoring.

This commit is contained in:
Emre Dogan 2023-10-05 18:34:58 +01:00
parent 82f7887931
commit b3465b269e
25 changed files with 1457 additions and 1328 deletions

View File

@ -1,5 +1,8 @@
using UnityEngine;
namespace Attributes
{
/// <summary> Draw enums correctly within nodes. Without it, enums show up at the wrong positions. </summary>
/// <remarks> Enums with this attribute are not detected by EditorGui.ChangeCheck due to waiting before executing </remarks>
public class NodeEnumAttribute : PropertyAttribute { }
}

View File

@ -1,4 +1,7 @@
using System;
namespace Attributes
{
/// <summary> Overrides the ValueType of the Port, to have a ValueType different from the type of its serializable field </summary>
/// <remarks> Especially useful in Dynamic Port Lists to create Value-Port Pairs with different type. </remarks>
[AttributeUsage(AttributeTargets.Field)]
@ -10,3 +13,4 @@ public class PortTypeOverrideAttribute : Attribute {
this.type = type;
}
}
}

View File

@ -1,9 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Attributes;
using UnityEditor;
using UnityEngine;
using XNode;
using XNodeEditor;
namespace XNodeEditor {

View File

@ -8,7 +8,7 @@ using Sirenix.Utilities.Editor;
namespace XNodeEditor {
/// <summary> Override graph inspector to show an 'Open Graph' button at the top </summary>
[CustomEditor(typeof(XNode.NodeGraph), true)]
[CustomEditor(typeof(NodeGraph), true)]
#if ODIN_INSPECTOR
public class GlobalGraphEditor : OdinEditor {
public override void OnInspectorGUI() {
@ -25,7 +25,7 @@ namespace XNodeEditor {
serializedObject.Update();
if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
NodeEditorWindow.Open(serializedObject.targetObject as XNode.NodeGraph);
NodeEditorWindow.Open(serializedObject.targetObject as NodeGraph);
}
GUILayout.Space(EditorGUIUtility.singleLineHeight);
@ -38,7 +38,7 @@ namespace XNodeEditor {
}
#endif
[CustomEditor(typeof(XNode.Node), true)]
[CustomEditor(typeof(Node), true)]
#if ODIN_INSPECTOR
public class GlobalNodeEditor : OdinEditor {
public override void OnInspectorGUI() {
@ -58,7 +58,7 @@ namespace XNodeEditor {
if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
SerializedProperty graphProp = serializedObject.FindProperty("graph");
NodeEditorWindow w = NodeEditorWindow.Open(graphProp.objectReferenceValue as XNode.NodeGraph);
NodeEditorWindow w = NodeEditorWindow.Open(graphProp.objectReferenceValue as NodeGraph);
w.Home(); // Focus selected node
}

View File

@ -1,13 +1,12 @@
using UnityEditor;
using XNode;
namespace XNodeEditor {
/// <summary>
/// This asset processor resolves an issue with the new v2 AssetDatabase system present on 2019.3 and later. When
/// renaming a <see cref="XNode.NodeGraph"/> asset, it appears that sometimes the v2 AssetDatabase will swap which asset
/// is the main asset (present at top level) between the <see cref="XNode.NodeGraph"/> and one of its <see cref="XNode.Node"/>
/// renaming a <see cref="NodeGraph"/> asset, it appears that sometimes the v2 AssetDatabase will swap which asset
/// is the main asset (present at top level) between the <see cref="NodeGraph"/> and one of its <see cref="Node"/>
/// sub-assets. As a workaround until Unity fixes this, this asset processor checks all renamed assets and if it
/// finds a case where a <see cref="XNode.Node"/> has been made the main asset it will swap it back to being a sub-asset
/// finds a case where a <see cref="Node"/> has been made the main asset it will swap it back to being a sub-asset
/// and rename the node to the default name for that node type.
/// </summary>
internal sealed class GraphRenameFixAssetProcessor : AssetPostprocessor {

View File

@ -2,11 +2,11 @@
namespace XNodeEditor.Internal {
public struct RerouteReference {
public XNode.NodePort port;
public NodePort port;
public int connectionIndex;
public int pointIndex;
public RerouteReference(XNode.NodePort port, int connectionIndex, int pointIndex) {
public RerouteReference(NodePort port, int connectionIndex, int pointIndex) {
this.port = port;
this.connectionIndex = connectionIndex;
this.pointIndex = pointIndex;

View File

@ -14,12 +14,12 @@ using GenericMenu = XNodeEditor.AdvancedGenericMenu;
namespace XNodeEditor {
/// <summary> Base class to derive custom Node editors from. Use this to create your own custom inspectors and editors for your nodes. </summary>
[CustomNodeEditor(typeof(XNode.Node))]
public class NodeEditor : XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node> {
[CustomNodeEditor(typeof(Node))]
public class NodeEditor : XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, Node> {
/// <summary> Fires every whenever a node was modified through the editor </summary>
public static Action<XNode.Node> onUpdateNode;
public readonly static Dictionary<XNode.NodePort, Vector2> portPositions = new Dictionary<XNode.NodePort, Vector2>();
public static Action<Node> onUpdateNode;
public readonly static Dictionary<NodePort, Vector2> portPositions = new Dictionary<NodePort, Vector2>();
#if ODIN_INSPECTOR
protected internal static bool inNodeEditor = false;
@ -82,7 +82,7 @@ namespace XNodeEditor {
#endif
// Iterate through dynamic ports and draw them in the order in which they are serialized
foreach (XNode.NodePort dynamicPort in target.DynamicPorts) {
foreach (NodePort dynamicPort in target.DynamicPorts) {
if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
NodeEditorGUILayout.PortField(dynamicPort);
}
@ -136,8 +136,8 @@ namespace XNodeEditor {
public virtual void AddContextMenuItems(GenericMenu menu) {
bool canRemove = true;
// Actions if only one node is selected
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
XNode.Node node = Selection.activeObject as XNode.Node;
if (Selection.objects.Length == 1 && Selection.activeObject is Node) {
Node node = Selection.activeObject as Node;
menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node));
menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode);
@ -152,8 +152,8 @@ namespace XNodeEditor {
else menu.AddItem(new GUIContent("Remove"), false, null);
// Custom sctions if only one node is selected
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
XNode.Node node = Selection.activeObject as XNode.Node;
if (Selection.objects.Length == 1 && Selection.activeObject is Node) {
Node node = Selection.activeObject as Node;
menu.AddCustomContextMenuItems(node);
}
}
@ -171,7 +171,7 @@ namespace XNodeEditor {
[AttributeUsage(AttributeTargets.Class)]
public class CustomNodeEditorAttribute : Attribute,
XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node>.INodeEditorAttrib {
XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, Node>.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>

View File

@ -15,7 +15,7 @@ namespace XNodeEditor {
public static bool isPanning { get; private set; }
public static Vector2[] dragOffset;
public static XNode.Node[] copyBuffer = null;
public static Node[] copyBuffer = null;
public bool IsDraggingPort { get { return draggedOutput != null; } }
public bool IsHoveringPort { get { return hoveredPort != null; } }
@ -23,17 +23,17 @@ namespace XNodeEditor {
public bool IsHoveringReroute { get { return hoveredReroute.port != null; } }
/// <summary> Return the dragged port or null if not exist </summary>
public XNode.NodePort DraggedOutputPort { get { XNode.NodePort result = draggedOutput; return result; } }
public NodePort DraggedOutputPort { get { NodePort result = draggedOutput; return result; } }
/// <summary> Return the Hovered port or null if not exist </summary>
public XNode.NodePort HoveredPort { get { XNode.NodePort result = hoveredPort; return result; } }
public NodePort HoveredPort { get { NodePort result = hoveredPort; return result; } }
/// <summary> Return the Hovered node or null if not exist </summary>
public XNode.Node HoveredNode { get { XNode.Node result = hoveredNode; return result; } }
public Node HoveredNode { get { Node result = hoveredNode; return result; } }
private XNode.Node hoveredNode = null;
[NonSerialized] public XNode.NodePort hoveredPort = null;
[NonSerialized] private XNode.NodePort draggedOutput = null;
[NonSerialized] private XNode.NodePort draggedOutputTarget = null;
[NonSerialized] private XNode.NodePort autoConnectOutput = null;
private Node hoveredNode = null;
[NonSerialized] public NodePort hoveredPort = null;
[NonSerialized] private NodePort draggedOutput = null;
[NonSerialized] private NodePort draggedOutputTarget = null;
[NonSerialized] private NodePort autoConnectOutput = null;
[NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>();
private RerouteReference hoveredReroute = new RerouteReference();
@ -91,8 +91,8 @@ namespace XNodeEditor {
Vector2 mousePos = WindowToGridPosition(e.mousePosition);
// Move selected nodes with offset
for (int i = 0; i < Selection.objects.Length; i++) {
if (Selection.objects[i] is XNode.Node) {
XNode.Node node = Selection.objects[i] as XNode.Node;
if (Selection.objects[i] is Node) {
Node node = Selection.objects[i] as Node;
Undo.RecordObject(node, "Moved Node");
Vector2 initial = node.position;
node.position = mousePos + dragOffset[i];
@ -104,7 +104,7 @@ namespace XNodeEditor {
// Offset portConnectionPoints instantly if a node is dragged so they aren't delayed by a frame.
Vector2 offset = node.position - initial;
if (offset.sqrMagnitude > 0) {
foreach (XNode.NodePort output in node.Outputs) {
foreach (NodePort output in node.Outputs) {
Rect rect;
if (portConnectionPoints.TryGetValue(output, out rect)) {
rect.position += offset;
@ -112,7 +112,7 @@ namespace XNodeEditor {
}
}
foreach (XNode.NodePort input in node.Inputs) {
foreach (NodePort input in node.Inputs) {
Rect rect;
if (portConnectionPoints.TryGetValue(input, out rect)) {
rect.position += offset;
@ -167,8 +167,8 @@ namespace XNodeEditor {
hoveredPort.VerifyConnections();
autoConnectOutput = null;
if (hoveredPort.IsConnected) {
XNode.Node node = hoveredPort.node;
XNode.NodePort output = hoveredPort.Connection;
Node node = hoveredPort.node;
NodePort output = hoveredPort.Connection;
int outputConnectionIndex = output.GetConnectionIndex(hoveredPort);
draggedOutputReroutes = output.GetReroutePoints(outputConnectionIndex);
hoveredPort.Disconnect(output);
@ -222,7 +222,7 @@ namespace XNodeEditor {
if (IsDraggingPort) {
// If connection is valid, save it
if (draggedOutputTarget != null && graphEditor.CanConnect(draggedOutput, draggedOutputTarget)) {
XNode.Node node = draggedOutputTarget.node;
Node node = draggedOutputTarget.node;
if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget);
// ConnectionIndex can be -1 if the connection is removed instantly after creation
@ -245,8 +245,8 @@ namespace XNodeEditor {
EditorUtility.SetDirty(graph);
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else if (currentActivity == NodeActivity.DragNode) {
IEnumerable<XNode.Node> nodes = Selection.objects.Where(x => x is XNode.Node).Select(x => x as XNode.Node);
foreach (XNode.Node node in nodes) EditorUtility.SetDirty(node);
IEnumerable<Node> nodes = Selection.objects.Where(x => x is Node).Select(x => x as Node);
foreach (Node node in nodes) EditorUtility.SetDirty(node);
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
} else if (!IsHoveringNode) {
// If click outside node, release field focus
@ -316,12 +316,12 @@ namespace XNodeEditor {
if (e.keyCode == KeyCode.F2) RenameSelectedNode();
}
if (e.keyCode == KeyCode.A) {
if (Selection.objects.Any(x => graph.nodes.Contains(x as XNode.Node))) {
foreach (XNode.Node node in graph.nodes) {
if (Selection.objects.Any(x => graph.nodes.Contains(x as Node))) {
foreach (Node node in graph.nodes) {
DeselectNode(node);
}
} else {
foreach (XNode.Node node in graph.nodes) {
foreach (Node node in graph.nodes) {
SelectNode(node, true);
}
}
@ -366,8 +366,8 @@ namespace XNodeEditor {
dragOffset = new Vector2[Selection.objects.Length + selectedReroutes.Count];
// Selected nodes
for (int i = 0; i < Selection.objects.Length; i++) {
if (Selection.objects[i] is XNode.Node) {
XNode.Node node = Selection.objects[i] as XNode.Node;
if (Selection.objects[i] is Node) {
Node node = Selection.objects[i] as Node;
dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition);
}
}
@ -380,7 +380,7 @@ namespace XNodeEditor {
/// <summary> Puts all selected nodes in focus. If no nodes are present, resets view and zoom to to origin </summary>
public void Home() {
var nodes = Selection.objects.Where(o => o is XNode.Node).Cast<XNode.Node>().ToList();
var nodes = Selection.objects.Where(o => o is Node).Cast<Node>().ToList();
if (nodes.Count > 0) {
Vector2 minPos = nodes.Select(x => x.position).Aggregate((x, y) => new Vector2(Mathf.Min(x.x, y.x), Mathf.Min(x.y, y.y)));
Vector2 maxPos = nodes.Select(x => x.position + (nodeSizes.ContainsKey(x) ? nodeSizes[x] : Vector2.zero)).Aggregate((x, y) => new Vector2(Mathf.Max(x.x, y.x), Mathf.Max(x.y, y.y)));
@ -400,8 +400,8 @@ namespace XNodeEditor {
}
selectedReroutes.Clear();
foreach (UnityEngine.Object item in Selection.objects) {
if (item is XNode.Node) {
XNode.Node node = item as XNode.Node;
if (item is Node) {
Node node = item as Node;
graphEditor.RemoveNode(node);
}
}
@ -409,8 +409,8 @@ namespace XNodeEditor {
/// <summary> Initiate a rename on the currently selected node </summary>
public void RenameSelectedNode() {
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
XNode.Node node = Selection.activeObject as XNode.Node;
if (Selection.objects.Length == 1 && Selection.activeObject is Node) {
Node node = Selection.activeObject as Node;
Vector2 size;
if (nodeSizes.TryGetValue(node, out size)) {
RenamePopup.Show(Selection.activeObject, size.x);
@ -421,7 +421,7 @@ namespace XNodeEditor {
}
/// <summary> Draw this node on top of other nodes by placing it last in the graph.nodes list </summary>
public void MoveNodeToTop(XNode.Node node) {
public void MoveNodeToTop(Node node) {
int index;
while ((index = graph.nodes.IndexOf(node)) != graph.nodes.Count - 1) {
graph.nodes[index] = graph.nodes[index + 1];
@ -432,7 +432,7 @@ namespace XNodeEditor {
/// <summary> Duplicate selected nodes and select the duplicates </summary>
public void DuplicateSelectedNodes() {
// Get selected nodes which are part of this graph
XNode.Node[] selectedNodes = Selection.objects.Select(x => x as XNode.Node).Where(x => x != null && x.graph == graph).ToArray();
Node[] selectedNodes = Selection.objects.Select(x => x as Node).Where(x => x != null && x.graph == graph).ToArray();
if (selectedNodes == null || selectedNodes.Length == 0) return;
// Get top left node position
Vector2 topLeftNode = selectedNodes.Select(x => x.position).Aggregate((x, y) => new Vector2(Mathf.Min(x.x, y.x), Mathf.Min(x.y, y.y)));
@ -440,14 +440,14 @@ namespace XNodeEditor {
}
public void CopySelectedNodes() {
copyBuffer = Selection.objects.Select(x => x as XNode.Node).Where(x => x != null && x.graph == graph).ToArray();
copyBuffer = Selection.objects.Select(x => x as Node).Where(x => x != null && x.graph == graph).ToArray();
}
public void PasteNodes(Vector2 pos) {
InsertDuplicateNodes(copyBuffer, pos);
}
private void InsertDuplicateNodes(XNode.Node[] nodes, Vector2 topLeft) {
private void InsertDuplicateNodes(Node[] nodes, Vector2 topLeft) {
if (nodes == null || nodes.Length == 0) return;
// Get top-left node
@ -455,20 +455,20 @@ namespace XNodeEditor {
Vector2 offset = topLeft - topLeftNode;
UnityEngine.Object[] newNodes = new UnityEngine.Object[nodes.Length];
Dictionary<XNode.Node, XNode.Node> substitutes = new Dictionary<XNode.Node, XNode.Node>();
Dictionary<Node, Node> substitutes = new Dictionary<Node, Node>();
for (int i = 0; i < nodes.Length; i++) {
XNode.Node srcNode = nodes[i];
Node srcNode = nodes[i];
if (srcNode == null) continue;
// Check if user is allowed to add more of given node type
XNode.Node.DisallowMultipleNodesAttribute disallowAttrib;
Node.DisallowMultipleNodesAttribute disallowAttrib;
Type nodeType = srcNode.GetType();
if (NodeEditorUtilities.GetAttrib(nodeType, out disallowAttrib)) {
int typeCount = graph.nodes.Count(x => x.GetType() == nodeType);
if (typeCount >= disallowAttrib.max) continue;
}
XNode.Node newNode = graphEditor.CopyNode(srcNode);
Node newNode = graphEditor.CopyNode(srcNode);
substitutes.Add(srcNode, newNode);
newNode.position = srcNode.position + offset;
newNodes[i] = newNode;
@ -476,14 +476,14 @@ namespace XNodeEditor {
// Walk through the selected nodes again, recreate connections, using the new nodes
for (int i = 0; i < nodes.Length; i++) {
XNode.Node srcNode = nodes[i];
Node srcNode = nodes[i];
if (srcNode == null) continue;
foreach (XNode.NodePort port in srcNode.Ports) {
foreach (NodePort port in srcNode.Ports) {
for (int c = 0; c < port.ConnectionCount; c++) {
XNode.NodePort inputPort = port.direction == XNode.NodePort.IO.Input ? port : port.GetConnection(c);
XNode.NodePort outputPort = port.direction == XNode.NodePort.IO.Output ? port : port.GetConnection(c);
NodePort inputPort = port.direction == NodePort.IO.Input ? port : port.GetConnection(c);
NodePort outputPort = port.direction == NodePort.IO.Output ? port : port.GetConnection(c);
XNode.Node newNodeIn, newNodeOut;
Node newNodeIn, newNodeOut;
if (substitutes.TryGetValue(inputPort.node, out newNodeIn) && substitutes.TryGetValue(outputPort.node, out newNodeOut)) {
newNodeIn.UpdatePorts();
newNodeOut.UpdatePorts();
@ -537,7 +537,7 @@ namespace XNodeEditor {
}
}
bool IsHoveringTitle(XNode.Node node) {
bool IsHoveringTitle(Node node) {
Vector2 mousePos = Event.current.mousePosition;
//Get node position
Vector2 nodePos = GridToWindowPosition(node.position);
@ -550,11 +550,11 @@ namespace XNodeEditor {
}
/// <summary> Attempt to connect dragged output to target node </summary>
public void AutoConnect(XNode.Node node) {
public void AutoConnect(Node node) {
if (autoConnectOutput == null) return;
// Find compatible input port
XNode.NodePort inputPort = node.Ports.FirstOrDefault(x => x.IsInput && graphEditor.CanConnect(autoConnectOutput, x));
NodePort inputPort = node.Ports.FirstOrDefault(x => x.IsInput && graphEditor.CanConnect(autoConnectOutput, x));
if (inputPort != null) autoConnectOutput.Connect(inputPort);
// Save changes

View File

@ -22,7 +22,7 @@ namespace XNodeEditor {
// Check script type. Return if deleting a non-node script
UnityEditor.MonoScript script = obj as UnityEditor.MonoScript;
System.Type scriptType = script.GetClass ();
if (scriptType == null || (scriptType != typeof (XNode.Node) && !scriptType.IsSubclassOf (typeof (XNode.Node)))) return AssetDeleteResult.DidNotDelete;
if (scriptType == null || (scriptType != typeof (Node) && !scriptType.IsSubclassOf (typeof (Node)))) return AssetDeleteResult.DidNotDelete;
// Find all ScriptableObjects using this script
string[] guids = AssetDatabase.FindAssets ("t:" + scriptType);
@ -30,7 +30,7 @@ namespace XNodeEditor {
string assetpath = AssetDatabase.GUIDToAssetPath (guids[i]);
Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath (assetpath);
for (int k = 0; k < objs.Length; k++) {
XNode.Node node = objs[k] as XNode.Node;
Node node = objs[k] as Node;
if (node.GetType () == scriptType) {
if (node != null && node.graph != null) {
// Delete the node and notify the user
@ -48,17 +48,17 @@ namespace XNodeEditor {
[InitializeOnLoadMethod]
private static void OnReloadEditor () {
// Find all NodeGraph assets
string[] guids = AssetDatabase.FindAssets ("t:" + typeof (XNode.NodeGraph));
string[] guids = AssetDatabase.FindAssets ("t:" + typeof (NodeGraph));
for (int i = 0; i < guids.Length; i++) {
string assetpath = AssetDatabase.GUIDToAssetPath (guids[i]);
XNode.NodeGraph graph = AssetDatabase.LoadAssetAtPath (assetpath, typeof (XNode.NodeGraph)) as XNode.NodeGraph;
NodeGraph graph = AssetDatabase.LoadAssetAtPath (assetpath, typeof (NodeGraph)) as NodeGraph;
graph.nodes.RemoveAll(x => x == null); //Remove null items
Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath (assetpath);
// Ensure that all sub node assets are present in the graph node list
for (int u = 0; u < objs.Length; u++) {
// Ignore null sub assets
if (objs[u] == null) continue;
if (!graph.nodes.Contains (objs[u] as XNode.Node)) graph.nodes.Add(objs[u] as XNode.Node);
if (!graph.nodes.Contains (objs[u] as Node)) graph.nodes.Add(objs[u] as Node);
}
}
}

View File

@ -13,7 +13,7 @@ namespace XNodeEditor {
public partial class NodeEditorWindow {
public NodeGraphEditor graphEditor;
private List<UnityEngine.Object> selectionCache;
private List<XNode.Node> culledNodes;
private List<Node> culledNodes;
/// <summary> 19 if docked, 22 if not </summary>
private int topPadding { get { return isDocked() ? 19 : 22; } }
/// <summary> Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run.</summary>
@ -113,7 +113,7 @@ namespace XNodeEditor {
}
/// <summary> Show right-click context menu for hovered port </summary>
void ShowPortContextMenu(XNode.NodePort hoveredPort) {
void ShowPortContextMenu(NodePort hoveredPort) {
GenericMenu contextMenu = new GenericMenu();
foreach (var port in hoveredPort.GetConnections()) {
var name = port.node.name;
@ -125,10 +125,10 @@ namespace XNodeEditor {
if (NodeEditorPreferences.GetSettings().createFilter) {
contextMenu.AddSeparator("");
if (hoveredPort.direction == XNode.NodePort.IO.Input)
graphEditor.AddContextMenuItems(contextMenu, hoveredPort.ValueType, XNode.NodePort.IO.Output);
if (hoveredPort.direction == NodePort.IO.Input)
graphEditor.AddContextMenuItems(contextMenu, hoveredPort.ValueType, NodePort.IO.Output);
else
graphEditor.AddContextMenuItems(contextMenu, hoveredPort.ValueType, XNode.NodePort.IO.Input);
graphEditor.AddContextMenuItems(contextMenu, hoveredPort.ValueType, NodePort.IO.Input);
}
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
@ -335,12 +335,12 @@ namespace XNodeEditor {
List<Vector2> gridPoints = new List<Vector2>(2);
Color col = GUI.color;
foreach (XNode.Node node in graph.nodes) {
foreach (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;
// Draw full connections and output > reroute
foreach (XNode.NodePort output in node.Outputs) {
foreach (NodePort output in node.Outputs) {
//Needs cleanup. Null checks are ugly
Rect fromRect;
if (!_portConnectionPoints.TryGetValue(output, out fromRect)) continue;
@ -349,7 +349,7 @@ namespace XNodeEditor {
GUIStyle portStyle = graphEditor.GetPortStyle(output);
for (int k = 0; k < output.ConnectionCount; k++) {
XNode.NodePort input = output.GetConnection(k);
NodePort input = output.GetConnection(k);
Gradient noodleGradient = graphEditor.GetNoodleGradient(output, input);
float noodleThickness = graphEditor.GetNoodleThickness(output, input);
@ -404,7 +404,7 @@ namespace XNodeEditor {
}
System.Reflection.MethodInfo onValidate = null;
if (Selection.activeObject != null && Selection.activeObject is XNode.Node) {
if (Selection.activeObject != null && Selection.activeObject is Node) {
onValidate = Selection.activeObject.GetType().GetMethod("OnValidate");
if (onValidate != null) EditorGUI.BeginChangeCheck();
}
@ -430,14 +430,14 @@ namespace XNodeEditor {
//Save guiColor so we can revert it
Color guiColor = GUI.color;
List<XNode.NodePort> removeEntries = new List<XNode.NodePort>();
List<NodePort> removeEntries = new List<NodePort>();
if (e.type == EventType.Layout) culledNodes = new List<XNode.Node>();
if (e.type == EventType.Layout) culledNodes = new List<Node>();
for (int n = 0; n < graph.nodes.Count; n++) {
// Skip null nodes. The user could be in the process of renaming scripts, so removing them at this point is not advisable.
if (graph.nodes[n] == null) continue;
if (n >= graph.nodes.Count) return;
XNode.Node node = graph.nodes[n];
Node node = graph.nodes[n];
// Culling
if (e.type == EventType.Layout) {
@ -529,14 +529,14 @@ namespace XNodeEditor {
//Check if we are hovering any of this nodes ports
//Check input ports
foreach (XNode.NodePort input in node.Inputs) {
foreach (NodePort input in node.Inputs) {
//Check if port rect is available
if (!portConnectionPoints.ContainsKey(input)) continue;
Rect r = GridToWindowRectNoClipped(portConnectionPoints[input]);
if (r.Contains(mousePos)) hoveredPort = input;
}
//Check all output ports
foreach (XNode.NodePort output in node.Outputs) {
foreach (NodePort output in node.Outputs) {
//Check if port rect is available
if (!portConnectionPoints.ContainsKey(output)) continue;
Rect r = GridToWindowRectNoClipped(portConnectionPoints[output]);
@ -556,7 +556,7 @@ namespace XNodeEditor {
if (onValidate != null && EditorGUI.EndChangeCheck()) onValidate.Invoke(Selection.activeObject, null);
}
private bool ShouldBeCulled(XNode.Node node) {
private bool ShouldBeCulled(Node node) {
Vector2 nodePos = GridToWindowPositionNoClipped(node.position);
if (nodePos.x / _zoom > position.width) return true; // Right

View File

@ -22,18 +22,18 @@ namespace XNodeEditor {
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
public static void PropertyField(SerializedProperty property, GUIContent label, bool includeChildren = true, params GUILayoutOption[] options) {
if (property == null) throw new NullReferenceException();
XNode.Node node = property.serializedObject.targetObject as XNode.Node;
XNode.NodePort port = node.GetPort(property.name);
Node node = property.serializedObject.targetObject as Node;
NodePort port = node.GetPort(property.name);
PropertyField(property, label, port, includeChildren);
}
/// <summary> Make a field for a serialized property. Manual node port override. </summary>
public static void PropertyField(SerializedProperty property, XNode.NodePort port, bool includeChildren = true, params GUILayoutOption[] options) {
public static void PropertyField(SerializedProperty property, NodePort port, bool includeChildren = true, params GUILayoutOption[] options) {
PropertyField(property, null, port, includeChildren, options);
}
/// <summary> Make a field for a serialized property. Manual node port override. </summary>
public static void PropertyField(SerializedProperty property, GUIContent label, XNode.NodePort port, bool includeChildren = true, params GUILayoutOption[] options) {
public static void PropertyField(SerializedProperty property, GUIContent label, 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
@ -44,10 +44,10 @@ namespace XNodeEditor {
List<PropertyAttribute> propertyAttributes = NodeEditorUtilities.GetCachedPropertyAttribs(port.node.GetType(), property.name);
// If property is an input, display a regular property field and put a port handle on the left side
if (port.direction == XNode.NodePort.IO.Input) {
if (port.direction == NodePort.IO.Input) {
// Get data from [Input] attribute
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
XNode.Node.InputAttribute inputAttribute;
Node.ShowBackingValue showBacking = Node.ShowBackingValue.Unconnected;
Node.InputAttribute inputAttribute;
bool dynamicPortList = false;
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out inputAttribute)) {
dynamicPortList = inputAttribute.dynamicPortList;
@ -55,8 +55,8 @@ namespace XNodeEditor {
}
bool usePropertyAttributes = dynamicPortList ||
showBacking == XNode.Node.ShowBackingValue.Never ||
(showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
showBacking == Node.ShowBackingValue.Never ||
(showBacking == Node.ShowBackingValue.Unconnected && port.IsConnected);
float spacePadding = 0;
string tooltip = null;
@ -79,22 +79,22 @@ namespace XNodeEditor {
if (dynamicPortList) {
Type type = GetType(property);
XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : Node.ConnectionType.Multiple;
DynamicPortList(property.name, type, property.serializedObject, port.direction, connectionType);
return;
}
switch (showBacking) {
case XNode.Node.ShowBackingValue.Unconnected:
case Node.ShowBackingValue.Unconnected:
// Display a label if port is connected
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName, tooltip));
// Display an editable property field if port is not connected
else EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
break;
case XNode.Node.ShowBackingValue.Never:
case Node.ShowBackingValue.Never:
// Display a label
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName, tooltip));
break;
case XNode.Node.ShowBackingValue.Always:
case Node.ShowBackingValue.Always:
// Display an editable property field
EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
break;
@ -104,10 +104,10 @@ namespace XNodeEditor {
float paddingLeft = NodeEditorWindow.current.graphEditor.GetPortStyle(port).padding.left;
rect.position = rect.position - new Vector2(16 + paddingLeft, -spacePadding);
// If property is an output, display a text label and put a port handle on the right side
} else if (port.direction == XNode.NodePort.IO.Output) {
} else if (port.direction == NodePort.IO.Output) {
// Get data from [Output] attribute
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
XNode.Node.OutputAttribute outputAttribute;
Node.ShowBackingValue showBacking = Node.ShowBackingValue.Unconnected;
Node.OutputAttribute outputAttribute;
bool dynamicPortList = false;
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out outputAttribute)) {
dynamicPortList = outputAttribute.dynamicPortList;
@ -115,8 +115,8 @@ namespace XNodeEditor {
}
bool usePropertyAttributes = dynamicPortList ||
showBacking == XNode.Node.ShowBackingValue.Never ||
(showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
showBacking == Node.ShowBackingValue.Never ||
(showBacking == Node.ShowBackingValue.Unconnected && port.IsConnected);
float spacePadding = 0;
string tooltip = null;
@ -139,22 +139,22 @@ namespace XNodeEditor {
if (dynamicPortList) {
Type type = GetType(property);
XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : Node.ConnectionType.Multiple;
DynamicPortList(property.name, type, property.serializedObject, port.direction, connectionType);
return;
}
switch (showBacking) {
case XNode.Node.ShowBackingValue.Unconnected:
case Node.ShowBackingValue.Unconnected:
// Display a label if port is connected
if (port.IsConnected) EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName, tooltip), NodeEditorResources.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 XNode.Node.ShowBackingValue.Never:
case Node.ShowBackingValue.Never:
// Display a label
EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName, tooltip), NodeEditorResources.OutputPort, GUILayout.MinWidth(30));
break;
case XNode.Node.ShowBackingValue.Always:
case Node.ShowBackingValue.Always:
// Display an editable property field
EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30));
break;
@ -185,19 +185,19 @@ namespace XNodeEditor {
}
/// <summary> Make a simple port field. </summary>
public static void PortField(XNode.NodePort port, params GUILayoutOption[] options) {
public static void PortField(NodePort port, params GUILayoutOption[] options) {
PortField(null, port, options);
}
/// <summary> Make a simple port field. </summary>
public static void PortField(GUIContent label, XNode.NodePort port, params GUILayoutOption[] options) {
public static void PortField(GUIContent label, NodePort port, params GUILayoutOption[] options) {
if (port == null) return;
if (options == null) options = new GUILayoutOption[] { GUILayout.MinWidth(30) };
Vector2 position = Vector3.zero;
GUIContent content = label != null ? label : new GUIContent(ObjectNames.NicifyVariableName(port.fieldName));
// If property is an input, display a regular property field and put a port handle on the left side
if (port.direction == XNode.NodePort.IO.Input) {
if (port.direction == NodePort.IO.Input) {
// Display a label
EditorGUILayout.LabelField(content, options);
@ -206,7 +206,7 @@ namespace XNodeEditor {
position = rect.position - new Vector2(16 + paddingLeft, 0);
}
// If property is an output, display a text label and put a port handle on the right side
else if (port.direction == XNode.NodePort.IO.Output) {
else if (port.direction == NodePort.IO.Output) {
// Display a label
EditorGUILayout.LabelField(content, NodeEditorResources.OutputPort, options);
@ -218,7 +218,7 @@ namespace XNodeEditor {
}
/// <summary> Make a simple port field. </summary>
public static void PortField(Vector2 position, XNode.NodePort port) {
public static void PortField(Vector2 position, NodePort port) {
if (port == null) return;
Rect rect = new Rect(position, new Vector2(16, 16));
@ -235,17 +235,17 @@ namespace XNodeEditor {
}
/// <summary> Add a port field to previous layout element. </summary>
public static void AddPortField(XNode.NodePort port) {
public static void AddPortField(NodePort port) {
if (port == null) return;
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 == XNode.NodePort.IO.Input) {
if (port.direction == NodePort.IO.Input) {
rect = GUILayoutUtility.GetLastRect();
float paddingLeft = NodeEditorWindow.current.graphEditor.GetPortStyle(port).padding.left;
rect.position = rect.position - new Vector2(16 + paddingLeft, 0);
// If property is an output, display a text label and put a port handle on the right side
} else if (port.direction == XNode.NodePort.IO.Output) {
} else if (port.direction == NodePort.IO.Output) {
rect = GUILayoutUtility.GetLastRect();
rect.width += NodeEditorWindow.current.graphEditor.GetPortStyle(port).padding.right;
rect.position = rect.position + new Vector2(rect.width, 0);
@ -265,7 +265,7 @@ namespace XNodeEditor {
}
/// <summary> Draws an input and an output port on the same line </summary>
public static void PortPair(XNode.NodePort input, XNode.NodePort output) {
public static void PortPair(NodePort input, NodePort output) {
GUILayout.BeginHorizontal();
NodeEditorGUILayout.PortField(input, GUILayout.MinWidth(0));
NodeEditorGUILayout.PortField(output, GUILayout.MinWidth(0));
@ -292,18 +292,18 @@ namespace XNodeEditor {
#region Obsolete
[Obsolete("Use IsDynamicPortListPort instead")]
public static bool IsInstancePortListPort(XNode.NodePort port) {
public static bool IsInstancePortListPort(NodePort port) {
return IsDynamicPortListPort(port);
}
[Obsolete("Use DynamicPortList instead")]
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None, Action<ReorderableList> onCreation = null) {
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, NodePort.IO io, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = Node.TypeConstraint.None, Action<ReorderableList> onCreation = null) {
DynamicPortList(fieldName, type, serializedObject, io, connectionType, typeConstraint, onCreation);
}
#endregion
/// <summary> Is this port part of a DynamicPortList? </summary>
public static bool IsDynamicPortListPort(XNode.NodePort port) {
public static bool IsDynamicPortListPort(NodePort port) {
string[] parts = port.fieldName.Split(' ');
if (parts.Length != 2) return false;
Dictionary<string, ReorderableList> cache;
@ -320,8 +320,8 @@ namespace XNodeEditor {
/// <param name="serializedObject">The serializedObject of the node</param>
/// <param name="connectionType">Connection type of added dynamic ports</param>
/// <param name="onCreation">Called on the list on creation. Use this if you want to customize the created ReorderableList</param>
public static void DynamicPortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None, Action<ReorderableList> onCreation = null) {
XNode.Node node = serializedObject.targetObject as XNode.Node;
public static void DynamicPortList(string fieldName, Type type, SerializedObject serializedObject, NodePort.IO io, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = Node.TypeConstraint.None, Action<ReorderableList> onCreation = null) {
Node node = serializedObject.targetObject as Node;
var indexedPorts = node.DynamicPorts.Select(x => {
string[] split = x.fieldName.Split(' ');
@ -331,9 +331,9 @@ namespace XNodeEditor {
return new { index = i, port = x };
}
}
return new { index = -1, port = (XNode.NodePort)null };
return new { index = -1, port = (NodePort)null };
}).Where(x => x.port != null);
List<XNode.NodePort> dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
List<NodePort> dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
node.UpdatePorts();
@ -354,15 +354,15 @@ namespace XNodeEditor {
}
private static ReorderableList CreateReorderableList(string fieldName, List<XNode.NodePort> dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) {
private static ReorderableList CreateReorderableList(string fieldName, List<NodePort> dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, NodePort.IO io, Node.ConnectionType connectionType, Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) {
bool hasArrayData = arrayData != null && arrayData.isArray;
XNode.Node node = serializedObject.targetObject as XNode.Node;
Node node = serializedObject.targetObject as Node;
ReorderableList list = new ReorderableList(dynamicPorts, null, true, true, true, true);
string label = arrayData != null ? arrayData.displayName : ObjectNames.NicifyVariableName(fieldName);
list.drawElementCallback =
(Rect rect, int index, bool isActive, bool isFocused) => {
XNode.NodePort port = node.GetPort(fieldName + " " + index);
NodePort port = node.GetPort(fieldName + " " + index);
if (hasArrayData && arrayData.propertyType != SerializedPropertyType.String) {
if (arrayData.arraySize <= index) {
EditorGUI.LabelField(rect, "Array[" + index + "] data out of range");
@ -402,8 +402,8 @@ namespace XNodeEditor {
// Move up
if (rl.index > reorderableListIndex) {
for (int i = reorderableListIndex; i < rl.index; ++i) {
XNode.NodePort port = node.GetPort(fieldName + " " + i);
XNode.NodePort nextPort = node.GetPort(fieldName + " " + (i + 1));
NodePort port = node.GetPort(fieldName + " " + i);
NodePort nextPort = node.GetPort(fieldName + " " + (i + 1));
port.SwapConnections(nextPort);
// Swap cached positions to mitigate twitching
@ -416,8 +416,8 @@ namespace XNodeEditor {
// Move down
else {
for (int i = reorderableListIndex; i > rl.index; --i) {
XNode.NodePort port = node.GetPort(fieldName + " " + i);
XNode.NodePort nextPort = node.GetPort(fieldName + " " + (i - 1));
NodePort port = node.GetPort(fieldName + " " + i);
NodePort nextPort = node.GetPort(fieldName + " " + (i - 1));
port.SwapConnections(nextPort);
// Swap cached positions to mitigate twitching
@ -449,7 +449,7 @@ namespace XNodeEditor {
int i = 0;
while (node.HasPort(newName)) newName = fieldName + " " + (++i);
if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, XNode.Node.TypeConstraint.None, newName);
if (io == NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, Node.TypeConstraint.None, newName);
else node.AddDynamicInput(type, connectionType, typeConstraint, newName);
serializedObject.Update();
EditorUtility.SetDirty(node);
@ -469,7 +469,7 @@ namespace XNodeEditor {
return new { index = i, port = x };
}
}
return new { index = -1, port = (XNode.NodePort)null };
return new { index = -1, port = (NodePort)null };
}).Where(x => x.port != null);
dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
@ -486,7 +486,7 @@ namespace XNodeEditor {
// Move following connections one step up to replace the missing connection
for (int k = index + 1; k < dynamicPorts.Count(); k++) {
for (int j = 0; j < dynamicPorts[k].ConnectionCount; j++) {
XNode.NodePort other = dynamicPorts[k].GetConnection(j);
NodePort other = dynamicPorts[k].GetConnection(j);
dynamicPorts[k].Disconnect(other);
dynamicPorts[k - 1].Connect(other);
}
@ -523,7 +523,7 @@ namespace XNodeEditor {
string newName = arrayData.name + " 0";
int i = 0;
while (node.HasPort(newName)) newName = arrayData.name + " " + (++i);
if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, typeConstraint, newName);
if (io == NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, typeConstraint, newName);
else node.AddDynamicInput(type, connectionType, typeConstraint, newName);
EditorUtility.SetDirty(node);
dynamicPortCount++;

View File

@ -28,13 +28,13 @@ namespace XNodeEditor {
public static Type[] GetNodeTypes() {
//Get all classes deriving from Node via reflection
return GetDerivedTypes(typeof(XNode.Node));
return GetDerivedTypes(typeof(Node));
}
/// <summary> Custom node tint colors defined with [NodeColor(r, g, b)] </summary>
public static bool TryGetAttributeTint(this Type nodeType, out Color tint) {
if (nodeTint == null) {
CacheAttributes<Color, XNode.Node.NodeTintAttribute>(ref nodeTint, x => x.color);
CacheAttributes<Color, Node.NodeTintAttribute>(ref nodeTint, x => x.color);
}
return nodeTint.TryGetValue(nodeType, out tint);
}
@ -42,7 +42,7 @@ namespace XNodeEditor {
/// <summary> Get custom node widths defined with [NodeWidth(width)] </summary>
public static bool TryGetAttributeWidth(this Type nodeType, out int width) {
if (nodeWidth == null) {
CacheAttributes<int, XNode.Node.NodeWidthAttribute>(ref nodeWidth, x => x.width);
CacheAttributes<int, Node.NodeWidthAttribute>(ref nodeWidth, x => x.width);
}
return nodeWidth.TryGetValue(nodeType, out width);
}
@ -62,7 +62,7 @@ namespace XNodeEditor {
// If we can't find field in the first run, it's probably a private field in a base class.
FieldInfo field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
// Search base classes for private fields only. Public fields are found above
while (field == null && (type = type.BaseType) != typeof(XNode.Node)) field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
while (field == null && (type = type.BaseType) != typeof(Node)) field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
return field;
}

View File

@ -134,14 +134,14 @@ namespace XNodeEditor {
/// <param name="compatibleType">Type to find compatiblities</param>
/// <param name="direction"></param>
/// <returns>True if NodeType has some port with value type compatible</returns>
public static bool HasCompatiblePortType(Type nodeType, Type compatibleType, XNode.NodePort.IO direction = XNode.NodePort.IO.Input) {
Type findType = typeof(XNode.Node.InputAttribute);
if (direction == XNode.NodePort.IO.Output)
findType = typeof(XNode.Node.OutputAttribute);
public static bool HasCompatiblePortType(Type nodeType, Type compatibleType, NodePort.IO direction = NodePort.IO.Input) {
Type findType = typeof(Node.InputAttribute);
if (direction == NodePort.IO.Output)
findType = typeof(Node.OutputAttribute);
//Get All fields from node type and we go filter only field with portAttribute.
//This way is possible to know the values of the all ports and if have some with compatible value tue
foreach (FieldInfo f in XNode.NodeDataCache.GetNodeFields(nodeType)) {
foreach (FieldInfo f in NodeDataCache.GetNodeFields(nodeType)) {
var portAttribute = f.GetCustomAttributes(findType, false).FirstOrDefault();
if (portAttribute != null) {
if (IsCastableTo(f.FieldType, compatibleType)) {
@ -159,7 +159,7 @@ namespace XNodeEditor {
/// <param name="nodeTypes">List with all nodes type to filter</param>
/// <param name="compatibleType">Compatible Type to Filter</param>
/// <returns>Return Only Node Types with ports compatible, or an empty list</returns>
public static List<Type> GetCompatibleNodesTypes(Type[] nodeTypes, Type compatibleType, XNode.NodePort.IO direction = XNode.NodePort.IO.Input) {
public static List<Type> GetCompatibleNodesTypes(Type[] nodeTypes, Type compatibleType, NodePort.IO direction = NodePort.IO.Input) {
//Result List
List<Type> filteredTypes = new List<Type>();

View File

@ -11,8 +11,8 @@ namespace XNodeEditor {
public static NodeEditorWindow current;
/// <summary> Stores node positions for all nodePorts. </summary>
public Dictionary<XNode.NodePort, Rect> portConnectionPoints { get { return _portConnectionPoints; } }
private Dictionary<XNode.NodePort, Rect> _portConnectionPoints = new Dictionary<XNode.NodePort, Rect>();
public Dictionary<NodePort, Rect> portConnectionPoints { get { return _portConnectionPoints; } }
private Dictionary<NodePort, Rect> _portConnectionPoints = new Dictionary<NodePort, Rect>();
[SerializeField] private NodePortReference[] _references = new NodePortReference[0];
[SerializeField] private Rect[] _rects = new Rect[0];
@ -25,15 +25,15 @@ namespace XNodeEditor {
private Func<bool> _isDocked;
[System.Serializable] private class NodePortReference {
[SerializeField] private XNode.Node _node;
[SerializeField] private Node _node;
[SerializeField] private string _name;
public NodePortReference(XNode.NodePort nodePort) {
public NodePortReference(NodePort nodePort) {
_node = nodePort.node;
_name = nodePort.fieldName;
}
public XNode.NodePort GetNodePort() {
public NodePort GetNodePort() {
if (_node == null) {
return null;
}
@ -59,16 +59,16 @@ namespace XNodeEditor {
int length = _references.Length;
if (length == _rects.Length) {
for (int i = 0; i < length; i++) {
XNode.NodePort nodePort = _references[i].GetNodePort();
NodePort nodePort = _references[i].GetNodePort();
if (nodePort != null)
_portConnectionPoints.Add(nodePort, _rects[i]);
}
}
}
public Dictionary<XNode.Node, Vector2> nodeSizes { get { return _nodeSizes; } }
private Dictionary<XNode.Node, Vector2> _nodeSizes = new Dictionary<XNode.Node, Vector2>();
public XNode.NodeGraph graph;
public Dictionary<Node, Vector2> nodeSizes { get { return _nodeSizes; } }
private Dictionary<Node, Vector2> _nodeSizes = new Dictionary<Node, Vector2>();
public 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, NodeEditorPreferences.GetSettings().minZoom, NodeEditorPreferences.GetSettings().maxZoom); Repaint(); } }
@ -97,7 +97,7 @@ namespace XNodeEditor {
/// <summary> Handle Selection Change events</summary>
private static void OnSelectionChanged() {
XNode.NodeGraph nodeGraph = Selection.activeObject as XNode.NodeGraph;
NodeGraph nodeGraph = Selection.activeObject as NodeGraph;
if (nodeGraph && !AssetDatabase.Contains(nodeGraph)) {
if (NodeEditorPreferences.GetSettings().openOnCreate) Open(nodeGraph);
}
@ -132,7 +132,7 @@ namespace XNodeEditor {
string path = EditorUtility.SaveFilePanelInProject("Save NodeGraph", "NewNodeGraph", "asset", "");
if (string.IsNullOrEmpty(path)) return;
else {
XNode.NodeGraph existingGraph = AssetDatabase.LoadAssetAtPath<XNode.NodeGraph>(path);
NodeGraph existingGraph = AssetDatabase.LoadAssetAtPath<NodeGraph>(path);
if (existingGraph != null) AssetDatabase.DeleteAsset(path);
AssetDatabase.CreateAsset(graph, path);
EditorUtility.SetDirty(graph);
@ -171,7 +171,7 @@ namespace XNodeEditor {
return new Vector2(xOffset, yOffset);
}
public void SelectNode(XNode.Node node, bool add) {
public void SelectNode(Node node, bool add) {
if (add) {
List<Object> selection = new List<Object>(Selection.objects);
selection.Add(node);
@ -179,7 +179,7 @@ namespace XNodeEditor {
} else Selection.objects = new Object[] { node };
}
public void DeselectNode(XNode.Node node) {
public void DeselectNode(Node node) {
List<Object> selection = new List<Object>(Selection.objects);
selection.Remove(node);
Selection.objects = selection.ToArray();
@ -187,7 +187,7 @@ namespace XNodeEditor {
[OnOpenAsset(0)]
public static bool OnOpen(int instanceID, int line) {
XNode.NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as XNode.NodeGraph;
NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph;
if (nodeGraph != null) {
Open(nodeGraph);
return true;
@ -196,7 +196,7 @@ namespace XNodeEditor {
}
/// <summary>Open the provided graph in the NodeEditor</summary>
public static NodeEditorWindow Open(XNode.NodeGraph graph) {
public static NodeEditorWindow Open(NodeGraph graph) {
if (!graph) return null;
NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;

View File

@ -8,8 +8,8 @@ using GenericMenu = XNodeEditor.AdvancedGenericMenu;
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 : XNodeEditor.Internal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, XNode.NodeGraph> {
[CustomNodeGraphEditor(typeof(NodeGraph))]
public class NodeGraphEditor : XNodeEditor.Internal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, NodeGraph> {
[Obsolete("Use window.position instead")]
public Rect position { get { return window.position; } set { window.position = value; } }
/// <summary> Are we currently renaming a node? </summary>
@ -42,7 +42,7 @@ namespace XNodeEditor {
/// <summary> Returns context node menu path. Null or empty strings for hidden nodes. </summary>
public virtual string GetNodeMenuName(Type type) {
//Check if type has the CreateNodeMenuAttribute
XNode.Node.CreateNodeMenuAttribute attrib;
Node.CreateNodeMenuAttribute attrib;
if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path
return attrib.menuName;
else // Return generated path
@ -52,7 +52,7 @@ namespace XNodeEditor {
/// <summary> The order by which the menu items are displayed. </summary>
public virtual int GetNodeMenuOrder(Type type) {
//Check if type has the CreateNodeMenuAttribute
XNode.Node.CreateNodeMenuAttribute attrib;
Node.CreateNodeMenuAttribute attrib;
if (NodeEditorUtilities.GetAttrib(type, out attrib)) // Return custom path
return attrib.order;
else
@ -62,7 +62,7 @@ namespace XNodeEditor {
/// <summary>
/// Called before connecting two ports in the graph view to see if the output port is compatible with the input port
/// </summary>
public virtual bool CanConnect(XNode.NodePort output, XNode.NodePort input) {
public virtual bool CanConnect(NodePort output, NodePort input) {
return output.CanConnectTo(input);
}
@ -73,7 +73,7 @@ namespace XNodeEditor {
/// <param name="menu"></param>
/// <param name="compatibleType">Use it to filter only nodes with ports value type, compatible with this type</param>
/// <param name="direction">Direction of the compatiblity</param>
public virtual void AddContextMenuItems(GenericMenu menu, Type compatibleType = null, XNode.NodePort.IO direction = XNode.NodePort.IO.Input) {
public virtual void AddContextMenuItems(GenericMenu menu, Type compatibleType = null, NodePort.IO direction = NodePort.IO.Input) {
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
Type[] nodeTypes;
@ -92,7 +92,7 @@ namespace XNodeEditor {
if (string.IsNullOrEmpty(path)) continue;
// Check if user is allowed to add more of given node type
XNode.Node.DisallowMultipleNodesAttribute disallowAttrib;
Node.DisallowMultipleNodesAttribute disallowAttrib;
bool disallowed = false;
if (NodeEditorUtilities.GetAttrib(type, out disallowAttrib)) {
int typeCount = target.nodes.Count(x => x.GetType() == type);
@ -102,7 +102,7 @@ namespace XNodeEditor {
// Add node entry to context menu
if (disallowed) menu.AddItem(new GUIContent(path), false, null);
else menu.AddItem(new GUIContent(path), false, () => {
XNode.Node node = CreateNode(type, pos);
Node node = CreateNode(type, pos);
if (node != null) NodeEditorWindow.current.AutoConnect(node); // handle null nodes to avoid nullref exceptions
});
}
@ -116,7 +116,7 @@ namespace XNodeEditor {
/// <summary> Returned gradient is used to color noodles </summary>
/// <param name="output"> The output this noodle comes from. Never null. </param>
/// <param name="input"> The output this noodle comes from. Can be null if we are dragging the noodle. </param>
public virtual Gradient GetNoodleGradient(XNode.NodePort output, XNode.NodePort input) {
public virtual Gradient GetNoodleGradient(NodePort output, NodePort input) {
Gradient grad = new Gradient();
// If dragging the noodle, draw solid, slightly transparent
@ -147,20 +147,20 @@ namespace XNodeEditor {
/// <summary> Returned float is used for noodle thickness </summary>
/// <param name="output"> The output this noodle comes from. Never null. </param>
/// <param name="input"> The output this noodle comes from. Can be null if we are dragging the noodle. </param>
public virtual float GetNoodleThickness(XNode.NodePort output, XNode.NodePort input) {
public virtual float GetNoodleThickness(NodePort output, NodePort input) {
return NodeEditorPreferences.GetSettings().noodleThickness;
}
public virtual NoodlePath GetNoodlePath(XNode.NodePort output, XNode.NodePort input) {
public virtual NoodlePath GetNoodlePath(NodePort output, NodePort input) {
return NodeEditorPreferences.GetSettings().noodlePath;
}
public virtual NoodleStroke GetNoodleStroke(XNode.NodePort output, XNode.NodePort input) {
public virtual NoodleStroke GetNoodleStroke(NodePort output, NodePort input) {
return NodeEditorPreferences.GetSettings().noodleStroke;
}
/// <summary> Returned color is used to color ports </summary>
public virtual Color GetPortColor(XNode.NodePort port) {
public virtual Color GetPortColor(NodePort port) {
return GetTypeColor(port.ValueType);
}
@ -174,8 +174,8 @@ namespace XNodeEditor {
/// </summary>
/// <param name="port">the owner of the style</param>
/// <returns></returns>
public virtual GUIStyle GetPortStyle(XNode.NodePort port) {
if (port.direction == XNode.NodePort.IO.Input)
public virtual GUIStyle GetPortStyle(NodePort port) {
if (port.direction == NodePort.IO.Input)
return NodeEditorResources.styles.inputPort;
return NodeEditorResources.styles.outputPort;
@ -183,7 +183,7 @@ namespace XNodeEditor {
/// <summary> The returned color is used to color the background of the door.
/// Usually used for outer edge effect </summary>
public virtual Color GetPortBackgroundColor(XNode.NodePort port) {
public virtual Color GetPortBackgroundColor(NodePort port) {
return Color.gray;
}
@ -193,7 +193,7 @@ namespace XNodeEditor {
}
/// <summary> Override to display custom tooltips </summary>
public virtual string GetPortTooltip(XNode.NodePort port) {
public virtual string GetPortTooltip(NodePort port) {
Type portType = port.ValueType;
string tooltip = "";
tooltip = portType.PrettyName();
@ -210,9 +210,9 @@ namespace XNodeEditor {
}
/// <summary> Create a node and save it in the graph asset </summary>
public virtual XNode.Node CreateNode(Type type, Vector2 position) {
public virtual Node CreateNode(Type type, Vector2 position) {
Undo.RecordObject(target, "Create Node");
XNode.Node node = target.AddNode(type);
Node node = target.AddNode(type);
if (node == null) return null; // handle null nodes to avoid nullref exceptions
Undo.RegisterCreatedObjectUndo(node, "Create Node");
node.position = position;
@ -224,9 +224,9 @@ namespace XNodeEditor {
}
/// <summary> Creates a copy of the original node in the graph </summary>
public virtual XNode.Node CopyNode(XNode.Node original) {
public virtual Node CopyNode(Node original) {
Undo.RecordObject(target, "Duplicate Node");
XNode.Node node = target.CopyNode(original);
Node node = target.CopyNode(original);
Undo.RegisterCreatedObjectUndo(node, "Duplicate Node");
node.name = original.name;
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) AssetDatabase.AddObjectToAsset(node, target);
@ -235,11 +235,11 @@ namespace XNodeEditor {
}
/// <summary> Return false for nodes that can't be removed </summary>
public virtual bool CanRemove(XNode.Node node) {
public virtual bool CanRemove(Node node) {
// Check graph attributes to see if this node is required
Type graphType = target.GetType();
XNode.NodeGraph.RequireNodeAttribute[] attribs = Array.ConvertAll(
graphType.GetCustomAttributes(typeof(XNode.NodeGraph.RequireNodeAttribute), true), x => x as XNode.NodeGraph.RequireNodeAttribute);
NodeGraph.RequireNodeAttribute[] attribs = Array.ConvertAll(
graphType.GetCustomAttributes(typeof(NodeGraph.RequireNodeAttribute), true), x => x as NodeGraph.RequireNodeAttribute);
if (attribs.Any(x => x.Requires(node.GetType()))) {
if (target.nodes.Count(x => x.GetType() == node.GetType()) <= 1) {
return false;
@ -249,7 +249,7 @@ namespace XNodeEditor {
}
/// <summary> Safely remove a node and all its connections. </summary>
public virtual void RemoveNode(XNode.Node node) {
public virtual void RemoveNode(Node node) {
if (!CanRemove(node)) return;
// Remove the node
@ -265,7 +265,7 @@ namespace XNodeEditor {
[AttributeUsage(AttributeTargets.Class)]
public class CustomNodeGraphEditorAttribute : Attribute,
XNodeEditor.Internal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, XNode.NodeGraph>.INodeEditorAttrib {
XNodeEditor.Internal.NodeEditorBase<NodeGraphEditor, NodeGraphEditor.CustomNodeGraphEditorAttribute, NodeGraph>.INodeEditorAttrib {
private Type inspectedType;
public string editorPrefsKey;
/// <summary> Tells a NodeGraphEditor which Graph type it is an editor for </summary>

View File

@ -4,7 +4,6 @@ using System.Linq;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using XNode;
namespace XNodeEditor {
/// <summary> Deals with modified assets </summary>
@ -34,7 +33,7 @@ namespace XNodeEditor {
private static void AddRequired(NodeGraph graph, Type type, ref Vector2 position) {
if (!graph.nodes.Any(x => x.GetType() == type)) {
XNode.Node node = graph.AddNode(type);
Node node = graph.AddNode(type);
node.position = position;
position.x += 200;
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);

View File

@ -0,0 +1,109 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace XNodeEditor.NodeGroups {
[CustomNodeEditor(typeof(NodeGroup))]
public class NodeGroupEditor : NodeEditor {
private NodeGroup group { get { return _group != null ? _group : _group = target as NodeGroup; } }
private NodeGroup _group;
public static Texture2D corner { get { return _corner != null ? _corner : _corner = Resources.Load<Texture2D>("xnode_corner"); } }
private static Texture2D _corner;
private bool isDragging;
private Vector2 size;
public override void OnBodyGUI() {
Event e = Event.current;
switch (e.type) {
case EventType.MouseDrag:
if (isDragging) {
group.width = Mathf.Max(200, (int) e.mousePosition.x + 16);
group.height = Mathf.Max(100, (int) e.mousePosition.y - 34);
NodeEditorWindow.current.Repaint();
}
break;
case EventType.MouseDown:
// Ignore everything except left clicks
if (e.button != 0) return;
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size)) {
// Mouse position checking is in node local space
Rect lowerRight = new Rect(size.x - 34, size.y - 34, 30, 30);
if (lowerRight.Contains(e.mousePosition)) {
isDragging = true;
}
}
break;
case EventType.MouseUp:
isDragging = false;
// Select nodes inside the group
if (Selection.Contains(target)) {
List<Object> selection = Selection.objects.ToList();
// Select Nodes
selection.AddRange(group.GetNodes());
// Select Reroutes
foreach (Node node in target.graph.nodes) {
if (node != null)
{
foreach (NodePort port in node.Ports) {
for (int i = 0; i < port.ConnectionCount; i++) {
List<Vector2> reroutes = port.GetReroutePoints(i);
for (int k = 0; k < reroutes.Count; k++) {
Vector2 p = reroutes[k];
if (p.x < group.position.x) continue;
if (p.y < group.position.y) continue;
if (p.x > group.position.x + group.width) continue;
if (p.y > group.position.y + group.height + 30) continue;
if (NodeEditorWindow.current.selectedReroutes.Any(x => x.port == port && x.connectionIndex == i && x.pointIndex == k)) continue;
NodeEditorWindow.current.selectedReroutes.Add(
new Internal.RerouteReference(port, i, k)
);
}
}
}
}
else
{
continue;
}
}
Selection.objects = selection.Distinct().ToArray();
}
break;
case EventType.Repaint:
// Move to bottom
if (target.graph.nodes.IndexOf(target) != 0) {
target.graph.nodes.Remove(target);
target.graph.nodes.Insert(0, target);
}
// Add scale cursors
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size)) {
Rect lowerRight = new Rect(target.position, new Vector2(30, 30));
lowerRight.y += size.y - 34;
lowerRight.x += size.x - 34;
lowerRight = NodeEditorWindow.current.GridToWindowRect(lowerRight);
NodeEditorWindow.current.onLateGUI += () => AddMouseRect(lowerRight);
}
break;
}
// Control height of node
GUILayout.Space(group.height);
GUI.DrawTexture(new Rect(group.width - 34, group.height + 16, 24, 24), corner);
}
public override int GetWidth() {
return group.width;
}
public override Color GetTint() {
return group.color;
}
public static void AddMouseRect(Rect rect) {
EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeUpLeft);
}
}
}

View File

@ -52,9 +52,9 @@ namespace XNodeEditor {
if (input == null || input.Trim() == "") {
if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) {
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).OnRename();
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) {
AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
AssetDatabase.SetMainObject((target as Node).graph, AssetDatabase.GetAssetPath(target));
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
}
Close();
@ -65,9 +65,9 @@ namespace XNodeEditor {
else {
if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
target.name = input;
NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).OnRename();
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) {
AssetDatabase.SetMainObject((target as XNode.Node).graph, AssetDatabase.GetAssetPath(target));
AssetDatabase.SetMainObject((target as Node).graph, AssetDatabase.GetAssetPath(target));
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
}
Close();

View File

@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using XNode;
namespace XNodeEditor {
[CustomEditor(typeof(SceneGraph), true)]

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using UnityEngine;
namespace XNode {
/// <summary>
/// Base class for all nodes
/// </summary>
@ -418,4 +417,3 @@ namespace XNode {
}
}
}
}

View File

@ -3,7 +3,6 @@ using System.Linq;
using System.Reflection;
using UnityEngine;
namespace XNode {
/// <summary> Precaches reflection data in editor so we won't have to do it runtime </summary>
public static class NodeDataCache {
private static PortDataCache portDataCache;
@ -177,7 +176,7 @@ namespace XNode {
// GetFields doesnt return inherited private fields, so walk through base types and pick those up
System.Type tempType = nodeType;
while ((tempType = tempType.BaseType) != typeof(XNode.Node)) {
while ((tempType = tempType.BaseType) != typeof(Node)) {
FieldInfo[] parentFields = tempType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
for (int i = 0; i < parentFields.Length; i++) {
// Ensure that we do not already have a member with this type and name
@ -223,4 +222,3 @@ namespace XNode {
[System.Serializable]
private class PortDataCache : Dictionary<System.Type, Dictionary<string, NodePort>> { }
}
}

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using UnityEngine;
namespace XNode {
/// <summary> Base class for all node graphs </summary>
[Serializable]
public abstract class NodeGraph : ScriptableObject {
@ -54,7 +53,7 @@ namespace XNode {
}
/// <summary> Create a new deep copy of this graph </summary>
public virtual XNode.NodeGraph Copy() {
public virtual NodeGraph Copy() {
// Instantiate a new nodegraph instance
NodeGraph graph = Instantiate(this);
// Instantiate all nodes inside the graph
@ -121,4 +120,3 @@ namespace XNode {
}
#endregion
}
}

28
Scripts/NodeGroup.cs Normal file
View File

@ -0,0 +1,28 @@
using System.Collections.Generic;
using UnityEngine;
[CreateNodeMenu("Group")]
public class NodeGroup : Node {
public int width = 400;
public int height = 400;
public Color color = new Color(1f, 1f, 1f, 0.1f);
public override object GetValue(NodePort port) {
return null;
}
/// <summary> Gets nodes in this group </summary>
public List<Node> GetNodes() {
List<Node> result = new List<Node>();
foreach (Node node in graph.nodes) {
if (node == this) continue;
if (node == null) continue;
if (node.position.x < this.position.x) continue;
if (node.position.y < this.position.y) continue;
if (node.position.x > this.position.x + width) continue;
if (node.position.y > this.position.y + height + 30) continue;
result.Add(node);
}
return result;
}
}

View File

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Attributes;
using UnityEngine;
namespace XNode {
[Serializable]
public class NodePort {
public enum IO { Input, Output }
@ -275,15 +275,15 @@ namespace XNode {
// If there isn't one of each, they can't connect
if (input == null || output == null) return false;
// Check input type constraints
if (input.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false;
if (input.typeConstraint == XNode.Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false;
if (input.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (input.typeConstraint == XNode.Node.TypeConstraint.InheritedAny && !input.ValueType.IsAssignableFrom(output.ValueType) && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (input.typeConstraint == Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false;
if (input.typeConstraint == Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false;
if (input.typeConstraint == Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (input.typeConstraint == Node.TypeConstraint.InheritedAny && !input.ValueType.IsAssignableFrom(output.ValueType) && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
// Check output type constraints
if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false;
if (output.typeConstraint == XNode.Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false;
if (output.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (output.typeConstraint == XNode.Node.TypeConstraint.InheritedAny && !input.ValueType.IsAssignableFrom(output.ValueType) && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (output.typeConstraint == Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false;
if (output.typeConstraint == Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false;
if (output.typeConstraint == Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (output.typeConstraint == Node.TypeConstraint.InheritedAny && !input.ValueType.IsAssignableFrom(output.ValueType) && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
// Success
return true;
}
@ -419,4 +419,3 @@ namespace XNode {
}
}
}
}

View File

@ -1,9 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XNode;
using UnityEngine;
namespace XNode {
/// <summary> Lets you instantiate a node graph in the scene. This allows you to reference in-scene objects. </summary>
public class SceneGraph : MonoBehaviour {
public NodeGraph graph;
@ -20,4 +16,3 @@ namespace XNode {
public class SceneGraph<T> : SceneGraph where T : NodeGraph {
public new T graph { get { return base.graph as T; } set { base.graph = value; } }
}
}