diff --git a/Example/ExampleNodeGraph.asset b/Example/ExampleNodeGraph.asset
index 6aab2a7..d42f7ca 100644
Binary files a/Example/ExampleNodeGraph.asset and b/Example/ExampleNodeGraph.asset differ
diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs
index a6c1c84..093b175 100644
--- a/Scripts/Editor/NodeEditor.cs
+++ b/Scripts/Editor/NodeEditor.cs
@@ -111,19 +111,11 @@ public class NodeEditor {
EditorGUI.BeginChangeCheck();
if (fieldType == typeof(int)) {
- Rect rect = EditorGUILayout.GetControlRect();
- rect.width *= 0.5f;
- EditorGUI.LabelField(rect, fieldPrettyName);
- rect.x += rect.width;
- fieldValue = EditorGUI.IntField(rect, (int) fieldValue);
+ fieldValue = NodeEditorGUILayout.IntField(fieldPrettyName, (int) fieldValue);
} else if (fieldType == typeof(bool)) {
fieldValue = EditorGUILayout.Toggle(fieldPrettyName, (bool) fieldValue);
} else if (fieldType.IsEnum) {
- Rect rect = EditorGUILayout.GetControlRect();
- rect.width *= 0.5f;
- EditorGUI.LabelField(rect, fieldPrettyName);
- rect.x += rect.width;
- fieldValue = EditorGUI.EnumPopup(rect, (Enum) fieldValue);
+ fieldValue = NodeEditorGUILayout.EnumField(fieldPrettyName, (Enum)fieldValue);
} else if (fieldType == typeof(string)) {
if (fieldName == "name") return; //Ignore 'name'
@@ -136,11 +128,11 @@ public class NodeEditor {
if (fieldName == "rect") return; //Ignore 'rect'
fieldValue = EditorGUILayout.RectField(fieldPrettyName, (Rect) fieldValue);
} else if (fieldType == typeof(float)) {
- Rect rect = EditorGUILayout.GetControlRect();
- rect.width *= 0.5f;
- EditorGUI.LabelField(rect, fieldPrettyName);
- rect.x += rect.width;
- fieldValue = EditorGUI.FloatField(rect, (float) fieldValue);
+ fieldValue = NodeEditorGUILayout.FloatField(fieldPrettyName, (float) fieldValue);
+ } else if (fieldType == typeof(double)) {
+ fieldValue = NodeEditorGUILayout.DoubleField(fieldPrettyName, (double) fieldValue);
+ } else if (fieldType == typeof(long)) {
+ fieldValue = NodeEditorGUILayout.LongField(fieldPrettyName, (long) fieldValue);
} else if (fieldType == typeof(Vector2)) {
fieldValue = EditorGUILayout.Vector2Field(fieldPrettyName, (Vector2) fieldValue);
} else if (fieldType == typeof(Vector3)) {
diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs
new file mode 100644
index 0000000..e4d3b39
--- /dev/null
+++ b/Scripts/Editor/NodeEditorGUILayout.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+
+/// Provides unec-specific field editors
+public class NodeEditorGUILayout {
+
+ private static double tempValue;
+
+ public static int IntField(string label, int value) {
+ GUIUtility.GetControlID(FocusType.Passive);
+ Rect rect = EditorGUILayout.GetControlRect();
+ rect.width *= 0.5f;
+ if (NodeEditorWindow.current != null) {
+ double v = (double) value;
+ DragNumber(rect, ref v);
+ value = (int) v;
+ if (GUI.changed) NodeEditorWindow.current.Repaint();
+ }
+ EditorGUI.LabelField(rect, label);
+ rect.x += rect.width;
+ if (!GUI.changed) value = EditorGUI.IntField(rect, value);
+ else {
+ EditorGUI.IntField(rect, value);
+ }
+ return value;
+ }
+ public static float FloatField(string label, float value) {
+ GUIUtility.GetControlID(FocusType.Passive);
+ Rect rect = EditorGUILayout.GetControlRect();
+ rect.width *= 0.5f;
+ if (NodeEditorWindow.current != null) {
+ double v = (double) value;
+ DragNumber(rect, ref v);
+ value = (float) v;
+ if (GUI.changed) NodeEditorWindow.current.Repaint();
+ }
+ EditorGUI.LabelField(rect, label);
+ rect.x += rect.width;
+ if (!GUI.changed) value = EditorGUI.FloatField(rect, value);
+ else {
+ EditorGUI.FloatField(rect, value);
+ }
+ return value;
+ }
+ public static double DoubleField(string label, double value) {
+ GUIUtility.GetControlID(FocusType.Passive);
+ Rect rect = EditorGUILayout.GetControlRect();
+ rect.width *= 0.5f;
+ if (NodeEditorWindow.current != null) {
+ double v = (double) value;
+ DragNumber(rect, ref v);
+ value = (double) v;
+ if (GUI.changed) NodeEditorWindow.current.Repaint();
+ }
+ EditorGUI.LabelField(rect, label);
+ rect.x += rect.width;
+ if (!GUI.changed) value = EditorGUI.DoubleField(rect, value);
+ else {
+ EditorGUI.DoubleField(rect, value);
+ }
+ return value;
+ }
+ public static long LongField(string label, long value) {
+ GUIUtility.GetControlID(FocusType.Passive);
+ Rect rect = EditorGUILayout.GetControlRect();
+ rect.width *= 0.5f;
+ if (NodeEditorWindow.current != null) {
+ double v = (double) value;
+ DragNumber(rect, ref v);
+ value = (long) v;
+ if (GUI.changed) NodeEditorWindow.current.Repaint();
+ }
+ EditorGUI.LabelField(rect, label);
+ rect.x += rect.width;
+ if (!GUI.changed) value = EditorGUI.LongField(rect, value);
+ else {
+ EditorGUI.LongField(rect, value);
+ }
+ return value;
+ }
+ public static void DragNumber(Rect rect, ref double value) {
+ double sensitivity = Math.Max(0.09432981473891d, Math.Pow(Math.Abs(value), 0.5d) * 0.03d);
+
+ int id = GUIUtility.GetControlID(FocusType.Passive);
+ Event e = Event.current;
+ switch (e.type) {
+ case EventType.MouseDown:
+ if (rect.Contains(e.mousePosition) && e.button == 0) {
+ tempValue = value;
+ GUIUtility.hotControl = id;
+ e.Use();
+ GUIUtility.keyboardControl = id;
+ EditorGUIUtility.SetWantsMouseJumping(1);
+ }
+ break;
+ case EventType.MouseUp:
+ tempValue = 0;
+ if (GUIUtility.hotControl == id) {
+ GUIUtility.hotControl = 0;
+ e.Use();
+ EditorGUIUtility.SetWantsMouseJumping(0);
+ }
+ break;
+ case EventType.MouseDrag:
+ if (GUIUtility.hotControl == id) {
+ tempValue += HandleUtility.niceMouseDelta * sensitivity;
+ value = tempValue;
+ GUI.changed = true;
+ }
+ break;
+ case EventType.Repaint:
+ if (NodeEditorWindow.current != null && Mathf.Approximately(NodeEditorWindow.current.zoom, 1)) {
+ EditorGUIUtility.AddCursorRect(rect, MouseCursor.SlideArrow);
+ }
+ break;
+ }
+ }
+ public static Enum EnumField(string label, Enum value) {
+ Rect rect = EditorGUILayout.GetControlRect();
+ rect.width *= 0.5f;
+ EditorGUI.LabelField(rect, label);
+ rect.x += rect.width;
+ return EditorGUI.EnumPopup(rect, value);
+ }
+}
\ No newline at end of file
diff --git a/Scripts/Editor/NodeEditorGUILayout.cs.meta b/Scripts/Editor/NodeEditorGUILayout.cs.meta
new file mode 100644
index 0000000..89596e2
--- /dev/null
+++ b/Scripts/Editor/NodeEditorGUILayout.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1d6c2d118d1c77948a23f2f4a34d1f64
+timeCreated: 1507966608
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs
index 34e627d..caacf66 100644
--- a/Scripts/Editor/NodeEditorWindow.cs
+++ b/Scripts/Editor/NodeEditorWindow.cs
@@ -8,6 +8,8 @@ using UnityEngine;
[InitializeOnLoad]
public partial class NodeEditorWindow : EditorWindow {
+ public static NodeEditorWindow current;
+
/// Stores node positions for all nodePorts.
public Dictionary portConnectionPoints { get { return _portConnectionPoints; } }
private Dictionary _portConnectionPoints = new Dictionary();
@@ -19,6 +21,7 @@ public partial class NodeEditorWindow : EditorWindow {
void OnFocus() {
AssetDatabase.SaveAssets();
+ current = this;
}
partial void OnEnable();