mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Added noodle settings
This commit is contained in:
parent
dba4cd1842
commit
ae2b8f1d38
@ -151,15 +151,50 @@ namespace XNodeEditor {
|
||||
startPoint = GridToWindowPosition(startPoint);
|
||||
endPoint = GridToWindowPosition(endPoint);
|
||||
|
||||
Vector2 startTangent = startPoint;
|
||||
if (startPoint.x < endPoint.x) startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, 0.7f);
|
||||
else startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, -0.7f);
|
||||
switch (NodeEditorPreferences.noodleType) {
|
||||
case NodeEditorPreferences.NoodleType.Curve:
|
||||
Vector2 startTangent = startPoint;
|
||||
if (startPoint.x < endPoint.x) startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, 0.7f);
|
||||
else startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, -0.7f);
|
||||
|
||||
Vector2 endTangent = endPoint;
|
||||
if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f);
|
||||
else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f);
|
||||
|
||||
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4);
|
||||
Vector2 endTangent = endPoint;
|
||||
if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f);
|
||||
else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f);
|
||||
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4);
|
||||
break;
|
||||
case NodeEditorPreferences.NoodleType.Line:
|
||||
Handles.color = col;
|
||||
Handles.DrawAAPolyLine(5, startPoint, endPoint);
|
||||
break;
|
||||
case NodeEditorPreferences.NoodleType.Angled:
|
||||
Handles.color = col;
|
||||
if (startPoint.x <= endPoint.x - (50 / zoom)) {
|
||||
float midpoint = (startPoint.x + endPoint.x) * 0.5f;
|
||||
Vector2 start_1 = startPoint;
|
||||
Vector2 end_1 = endPoint;
|
||||
start_1.x = midpoint;
|
||||
end_1.x = midpoint;
|
||||
Handles.DrawAAPolyLine(5, startPoint, start_1);
|
||||
Handles.DrawAAPolyLine(5, start_1, end_1);
|
||||
Handles.DrawAAPolyLine(5, end_1, endPoint);
|
||||
} else {
|
||||
float midpoint = (startPoint.y + endPoint.y) * 0.5f;
|
||||
Vector2 start_1 = startPoint;
|
||||
Vector2 end_1 = endPoint;
|
||||
start_1.x += 25 / zoom;
|
||||
end_1.x -= 25 / zoom;
|
||||
Vector2 start_2 = start_1;
|
||||
Vector2 end_2 = end_1;
|
||||
start_2.y = midpoint;
|
||||
end_2.y = midpoint;
|
||||
Handles.DrawAAPolyLine(5, startPoint, start_1);
|
||||
Handles.DrawAAPolyLine(5, start_1, start_2);
|
||||
Handles.DrawAAPolyLine(5, start_2, end_2);
|
||||
Handles.DrawAAPolyLine(5, end_2, end_1);
|
||||
Handles.DrawAAPolyLine(5, end_1, endPoint);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Draws all connections </summary>
|
||||
|
||||
@ -5,6 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace XNodeEditor {
|
||||
public static class NodeEditorPreferences {
|
||||
public enum NoodleType { Curve, Line, Angled }
|
||||
|
||||
public static Texture2D gridTexture {
|
||||
get {
|
||||
@ -24,7 +25,8 @@ namespace XNodeEditor {
|
||||
private static Texture2D _crossTexture;
|
||||
|
||||
public static bool GridSnap { get { VerifyLoaded(); return settings.gridSnap; } }
|
||||
public static Color HighlightColor { get { VerifyLoaded(); return settings.highlightColor; } }
|
||||
public static Color HighlightColor { get { VerifyLoaded(); return settings.highlightColor; } }
|
||||
public static NoodleType noodleType { get { VerifyLoaded(); return settings.noodleType; } }
|
||||
|
||||
private static Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
|
||||
private static Settings settings;
|
||||
@ -37,6 +39,7 @@ namespace XNodeEditor {
|
||||
public bool gridSnap = true;
|
||||
public string typeColorsData = "";
|
||||
public Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
|
||||
public NoodleType noodleType = NoodleType.Curve;
|
||||
|
||||
public void OnAfterDeserialize() {
|
||||
// Deserialize typeColorsData
|
||||
@ -91,6 +94,7 @@ namespace XNodeEditor {
|
||||
//Label
|
||||
EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
|
||||
settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor);
|
||||
settings.noodleType = (NoodleType)EditorGUILayout.EnumPopup("Noodle type", (Enum)settings.noodleType);
|
||||
if (GUI.changed) {
|
||||
SavePrefs();
|
||||
NodeEditorWindow.RepaintAll();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user