diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 9bcbdc3..e78aaec 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -14,16 +14,25 @@ namespace XNodeEditor { public static XNode.Node[] copyBuffer = null; - private bool IsDraggingPort { get { return draggedOutput != null; } } - private bool IsHoveringPort { get { return hoveredPort != null; } } - private bool IsHoveringNode { get { return hoveredNode != null; } } - private bool IsHoveringReroute { get { return hoveredReroute.port != null; } } + public bool IsDraggingPort { get { return draggedOutput != null; } } + public bool IsHoveringPort { get { return hoveredPort != null; } } + public bool IsHoveringNode { get { return hoveredNode != null; } } + public bool IsHoveringReroute { get { return hoveredReroute.port != null; } } + + /// Return the dragged port or null if not exist + public XNode.NodePort DraggedOutputPort { get { XNode.NodePort result = draggedOutput; return result; } } + /// Return the Hovered port or null if not exist + public XNode.NodePort HoveredPort { get { XNode.NodePort result = hoveredPort; return result; } } + /// Return the Hovered node or null if not exist + public XNode.Node HoveredNode { get { XNode.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; [NonSerialized] private List draggedOutputReroutes = new List(); + private RerouteReference hoveredReroute = new RerouteReference(); public List selectedReroutes = new List(); private Vector2 dragBoxStart; @@ -478,7 +487,7 @@ namespace XNodeEditor { } } } - EditorUtility.SetDirty(graph); + EditorUtility.SetDirty(graph); // Select the new nodes Selection.objects = newNodes; } @@ -549,4 +558,4 @@ namespace XNodeEditor { autoConnectOutput = null; } } -} +} \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 21d6d0f..d914eff 100755 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -556,7 +556,7 @@ namespace XNodeEditor { } private void DrawTooltip() { - if (!NodeEditorPreferences.GetSettings().portTooltips || graphEditor is null) + if (!NodeEditorPreferences.GetSettings().portTooltips || graphEditor == null) return; string tooltip = null; if (hoveredPort != null) { diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 19e9ca5..1b74a32 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -73,7 +73,7 @@ namespace XNodeEditor { GUI.Label(position, (attr as HeaderAttribute).header, EditorStyles.boldLabel); } else spacePadding += EditorGUIUtility.singleLineHeight * 1.5f; } else if (attr is TooltipAttribute) { - tooltip = (attr as TooltipAttribute).tooltip; + tooltip = (attr as TooltipAttribute).tooltip; } } @@ -101,7 +101,8 @@ namespace XNodeEditor { } rect = GUILayoutUtility.GetLastRect(); - rect.position = rect.position - new Vector2(16, -spacePadding); + float paddingLeft = NodeEditorResources.styles.inputPort.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) { // Get data from [Output] attribute @@ -132,7 +133,7 @@ namespace XNodeEditor { GUI.Label(position, (attr as HeaderAttribute).header, EditorStyles.boldLabel); } else spacePadding += EditorGUIUtility.singleLineHeight * 1.5f; } else if (attr is TooltipAttribute) { - tooltip = (attr as TooltipAttribute).tooltip; + tooltip = (attr as TooltipAttribute).tooltip; } } @@ -160,13 +161,13 @@ namespace XNodeEditor { } rect = GUILayoutUtility.GetLastRect(); + rect.width += NodeEditorResources.styles.outputPort.padding.right; rect.position = rect.position + new Vector2(rect.width, spacePadding); } rect.size = new Vector2(16, 16); - NodeEditor editor = NodeEditor.GetEditor(port.node, NodeEditorWindow.current); - Color backgroundColor = editor.GetTint(); + Color backgroundColor = NodeEditorWindow.current.graphEditor.GetPortBackgroundColor(port); Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port); DrawPortHandle(rect, backgroundColor, col); @@ -200,7 +201,8 @@ namespace XNodeEditor { EditorGUILayout.LabelField(content, options); Rect rect = GUILayoutUtility.GetLastRect(); - position = rect.position - new Vector2(16, 0); + float paddingLeft = NodeEditorResources.styles.inputPort.padding.left; + 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) { @@ -208,6 +210,7 @@ namespace XNodeEditor { EditorGUILayout.LabelField(content, NodeEditorResources.OutputPort, options); Rect rect = GUILayoutUtility.GetLastRect(); + rect.width += NodeEditorResources.styles.outputPort.padding.right; position = rect.position + new Vector2(rect.width, 0); } PortField(position, port); @@ -219,8 +222,7 @@ namespace XNodeEditor { Rect rect = new Rect(position, new Vector2(16, 16)); - NodeEditor editor = NodeEditor.GetEditor(port.node, NodeEditorWindow.current); - Color backgroundColor = editor.GetTint(); + Color backgroundColor = NodeEditorWindow.current.graphEditor.GetPortBackgroundColor(port); Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port); DrawPortHandle(rect, backgroundColor, col); @@ -237,17 +239,18 @@ namespace XNodeEditor { // 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) { rect = GUILayoutUtility.GetLastRect(); - rect.position = rect.position - new Vector2(16, 0); + float paddingLeft = NodeEditorResources.styles.inputPort.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) { rect = GUILayoutUtility.GetLastRect(); + rect.width += NodeEditorResources.styles.outputPort.padding.right; rect.position = rect.position + new Vector2(rect.width, 0); } rect.size = new Vector2(16, 16); - NodeEditor editor = NodeEditor.GetEditor(port.node, NodeEditorWindow.current); - Color backgroundColor = editor.GetTint(); + Color backgroundColor = NodeEditorWindow.current.graphEditor.GetPortBackgroundColor(port); Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port); DrawPortHandle(rect, backgroundColor, col); @@ -319,7 +322,7 @@ namespace XNodeEditor { List dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList(); node.UpdatePorts(); - + ReorderableList list = null; Dictionary rlc; if (reorderableListCache.TryGetValue(serializedObject.targetObject, out rlc)) { @@ -334,7 +337,7 @@ namespace XNodeEditor { } list.list = dynamicPorts; list.DoLayoutList(); - + } private static ReorderableList CreateReorderableList(string fieldName, List dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action onCreation) { @@ -355,7 +358,7 @@ namespace XNodeEditor { EditorGUI.PropertyField(rect, itemData, true); } else EditorGUI.LabelField(rect, port != null ? port.fieldName : ""); if (port != null) { - Vector2 pos = rect.position + (port.IsOutput?new Vector2(rect.width + 6, 0) : new Vector2(-36, 0)); + Vector2 pos = rect.position + (port.IsOutput ? new Vector2(rect.width + 6, 0) : new Vector2(-36, 0)); NodeEditorGUILayout.PortField(pos, port); } }; @@ -391,8 +394,8 @@ namespace XNodeEditor { // Swap cached positions to mitigate twitching hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect); hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect); - NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect; - NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect; + NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect ? newRect : rect; + NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect ? rect : newRect; } } // Move down @@ -405,8 +408,8 @@ namespace XNodeEditor { // Swap cached positions to mitigate twitching hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect); hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect); - NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect; - NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect; + NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect ? newRect : rect; + NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect ? rect : newRect; } } // Apply changes @@ -520,4 +523,4 @@ namespace XNodeEditor { return list; } } -} +} \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorPreferences.cs b/Scripts/Editor/NodeEditorPreferences.cs index e5fa238..6165072 100644 --- a/Scripts/Editor/NodeEditorPreferences.cs +++ b/Scripts/Editor/NodeEditorPreferences.cs @@ -20,10 +20,10 @@ namespace XNodeEditor { [System.Serializable] public class Settings : ISerializationCallbackReceiver { - [SerializeField] private Color32 _gridLineColor = new Color(0.45f, 0.45f, 0.45f); + [SerializeField] private Color32 _gridLineColor = new Color(.23f, .23f, .23f); public Color32 gridLineColor { get { return _gridLineColor; } set { _gridLineColor = value; _gridTexture = null; _crossTexture = null; } } - [SerializeField] private Color32 _gridBgColor = new Color(0.18f, 0.18f, 0.18f); + [SerializeField] private Color32 _gridBgColor = new Color(.19f, .19f, .19f); public Color32 gridBgColor { get { return _gridBgColor; } set { _gridBgColor = value; _gridTexture = null; } } [Obsolete("Use maxZoom instead")] @@ -42,6 +42,8 @@ namespace XNodeEditor { [SerializeField] private string typeColorsData = ""; [NonSerialized] public Dictionary typeColors = new Dictionary(); [FormerlySerializedAs("noodleType")] public NoodlePath noodlePath = NoodlePath.Curvy; + public float noodleThickness = 2f; + public NoodleStroke noodleStroke = NoodleStroke.Full; private Texture2D _gridTexture; @@ -101,7 +103,7 @@ namespace XNodeEditor { public static SettingsProvider CreateXNodeSettingsProvider() { SettingsProvider provider = new SettingsProvider("Preferences/Node Editor", SettingsScope.User) { guiHandler = (searchContext) => { XNodeEditor.NodeEditorPreferences.PreferencesGUI(); }, - keywords = new HashSet(new [] { "xNode", "node", "editor", "graph", "connections", "noodles", "ports" }) + keywords = new HashSet(new [] { "xNode", "node", "editor", "graph", "connections", "noodles", "ports" }) }; return provider; } @@ -160,6 +162,7 @@ namespace XNodeEditor { EditorGUILayout.LabelField("Node", EditorStyles.boldLabel); settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor); settings.noodlePath = (NoodlePath) EditorGUILayout.EnumPopup("Noodle path", (Enum) settings.noodlePath); + settings.noodleThickness = EditorGUILayout.FloatField(new GUIContent("Noodle thickness", "Noodle Thickness of the node connections"), settings.noodleThickness); settings.noodleStroke = (NoodleStroke) EditorGUILayout.EnumPopup("Noodle stroke", (Enum) settings.noodleStroke); settings.portTooltips = EditorGUILayout.Toggle("Port Tooltips", settings.portTooltips); settings.dragToCreate = EditorGUILayout.Toggle(new GUIContent("Drag to Create", "Drag a port connection anywhere on the grid to create and connect a node"), settings.dragToCreate); diff --git a/Scripts/Editor/NodeEditorResources.cs b/Scripts/Editor/NodeEditorResources.cs index 0a84e0a..9a5cc1e 100644 --- a/Scripts/Editor/NodeEditorResources.cs +++ b/Scripts/Editor/NodeEditorResources.cs @@ -18,7 +18,7 @@ namespace XNodeEditor { public static Styles _styles = null; public static GUIStyle OutputPort { get { return new GUIStyle(EditorStyles.label) { alignment = TextAnchor.UpperRight }; } } public class Styles { - public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight; + public GUIStyle inputPort, outputPort, nodeHeader, nodeBody, tooltip, nodeHighlight; public Styles() { GUIStyle baseStyle = new GUIStyle("Label"); @@ -26,7 +26,11 @@ namespace XNodeEditor { inputPort = new GUIStyle(baseStyle); inputPort.alignment = TextAnchor.UpperLeft; - inputPort.padding.left = 10; + inputPort.padding.left = 0; + + outputPort = new GUIStyle(baseStyle); + outputPort.alignment = TextAnchor.UpperRight; + outputPort.padding.right = 0; nodeHeader = new GUIStyle(); nodeHeader.alignment = TextAnchor.MiddleCenter; diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 01de70e..dcc92a9 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -17,7 +17,7 @@ namespace XNodeEditor { /// Called when opened by NodeEditorWindow public virtual void OnOpen() { } - + /// Called when NodeEditorWindow gains focus public virtual void OnWindowFocus() { } @@ -125,7 +125,7 @@ namespace XNodeEditor { /// The output this noodle comes from. Never null. /// The output this noodle comes from. Can be null if we are dragging the noodle. public virtual float GetNoodleThickness(XNode.NodePort output, XNode.NodePort input) { - return 5f; + return NodeEditorPreferences.GetSettings().noodleThickness; } public virtual NoodlePath GetNoodlePath(XNode.NodePort output, XNode.NodePort input) { @@ -141,6 +141,12 @@ namespace XNodeEditor { return GetTypeColor(port.ValueType); } + /// The returned color is used to color the background of the door. + /// Usually used for outer edge effect + public virtual Color GetPortBackgroundColor(XNode.NodePort port) { + return Color.gray; + } + /// Returns generated color for a type. This color is editable in preferences public virtual Color GetTypeColor(Type type) { return NodeEditorPreferences.GetTypeColor(type); @@ -234,4 +240,4 @@ namespace XNodeEditor { } } } -} +} \ No newline at end of file