1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 17:26:02 +08:00

Added noodle settings

This commit is contained in:
Thor Brigsted 2018-01-27 00:43:24 +01:00
parent dba4cd1842
commit ae2b8f1d38
2 changed files with 48 additions and 9 deletions

View File

@ -151,6 +151,8 @@ namespace XNodeEditor {
startPoint = GridToWindowPosition(startPoint); startPoint = GridToWindowPosition(startPoint);
endPoint = GridToWindowPosition(endPoint); endPoint = GridToWindowPosition(endPoint);
switch (NodeEditorPreferences.noodleType) {
case NodeEditorPreferences.NoodleType.Curve:
Vector2 startTangent = startPoint; Vector2 startTangent = startPoint;
if (startPoint.x < endPoint.x) startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, 0.7f); 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); else startTangent.x = Mathf.LerpUnclamped(startPoint.x, endPoint.x, -0.7f);
@ -158,8 +160,41 @@ namespace XNodeEditor {
Vector2 endTangent = endPoint; Vector2 endTangent = endPoint;
if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f); 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); else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f);
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4); 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> /// <summary> Draws all connections </summary>

View File

@ -5,6 +5,7 @@ using UnityEngine;
namespace XNodeEditor { namespace XNodeEditor {
public static class NodeEditorPreferences { public static class NodeEditorPreferences {
public enum NoodleType { Curve, Line, Angled }
public static Texture2D gridTexture { public static Texture2D gridTexture {
get { get {
@ -25,6 +26,7 @@ namespace XNodeEditor {
public static bool GridSnap { get { VerifyLoaded(); return settings.gridSnap; } } 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 Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
private static Settings settings; private static Settings settings;
@ -37,6 +39,7 @@ namespace XNodeEditor {
public bool gridSnap = true; public bool gridSnap = true;
public string typeColorsData = ""; public string typeColorsData = "";
public Dictionary<string, Color> typeColors = new Dictionary<string, Color>(); public Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
public NoodleType noodleType = NoodleType.Curve;
public void OnAfterDeserialize() { public void OnAfterDeserialize() {
// Deserialize typeColorsData // Deserialize typeColorsData
@ -91,6 +94,7 @@ namespace XNodeEditor {
//Label //Label
EditorGUILayout.LabelField("Node", EditorStyles.boldLabel); EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor); settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor);
settings.noodleType = (NoodleType)EditorGUILayout.EnumPopup("Noodle type", (Enum)settings.noodleType);
if (GUI.changed) { if (GUI.changed) {
SavePrefs(); SavePrefs();
NodeEditorWindow.RepaintAll(); NodeEditorWindow.RepaintAll();