mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Merge pull request #300 from neoneper/Improvments - customization
Internal changes that allow for greater customization options
This commit is contained in:
commit
e3127a9135
@ -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; } }
|
||||
|
||||
/// <summary> Return the dragged port or null if not exist </summary>
|
||||
public XNode.NodePort DraggedOutputPort { get { XNode.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; } }
|
||||
/// <summary> Return the Hovered node or null if not exist </summary>
|
||||
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<Vector2> draggedOutputReroutes = new List<Vector2>();
|
||||
|
||||
private RerouteReference hoveredReroute = new RerouteReference();
|
||||
public List<RerouteReference> selectedReroutes = new List<RerouteReference>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
@ -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<XNode.NodePort> dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
|
||||
|
||||
node.UpdatePorts();
|
||||
|
||||
|
||||
ReorderableList list = null;
|
||||
Dictionary<string, ReorderableList> 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<XNode.NodePort> dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<string, Color> typeColors = new Dictionary<string, Color>();
|
||||
[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<string>(new [] { "xNode", "node", "editor", "graph", "connections", "noodles", "ports" })
|
||||
keywords = new HashSet<string>(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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -17,7 +17,7 @@ namespace XNodeEditor {
|
||||
|
||||
/// <summary> Called when opened by NodeEditorWindow </summary>
|
||||
public virtual void OnOpen() { }
|
||||
|
||||
|
||||
/// <summary> Called when NodeEditorWindow gains focus </summary>
|
||||
public virtual void OnWindowFocus() { }
|
||||
|
||||
@ -125,7 +125,7 @@ namespace XNodeEditor {
|
||||
/// <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) {
|
||||
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);
|
||||
}
|
||||
|
||||
/// <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) {
|
||||
return Color.gray;
|
||||
}
|
||||
|
||||
/// <summary> Returns generated color for a type. This color is editable in preferences </summary>
|
||||
public virtual Color GetTypeColor(Type type) {
|
||||
return NodeEditorPreferences.GetTypeColor(type);
|
||||
@ -234,4 +240,4 @@ namespace XNodeEditor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user