From f335ecfbb5b694079f80f728731b92adb64b1312 Mon Sep 17 00:00:00 2001 From: Thor Kramer Brigsted Date: Tue, 31 Oct 2017 11:25:49 +0100 Subject: [PATCH] Nodes now show unsupported value types as labels. --- Scripts/Editor/NodeEditor.cs | 2 +- Scripts/Editor/NodeEditorGUILayout.cs | 30 +++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 4cc842a..5352061 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -31,7 +31,7 @@ public class NodeEditor { EditorGUI.BeginChangeCheck(); FieldInfo[] fields = GetInspectorFields(target); for (int i = 0; i < fields.Length; i++) { - if (fields[i].Name == "graph" || fields[i].Name == "position") continue; + switch (fields[i].Name) { case "graph": case "position": case "inputs": case "outputs": continue; } NodeEditorGUILayout.PropertyField(target, fields[i], portPositions); } //If user changed a value, notify other scripts through onUpdateNode diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 47c1946..936e6b9 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -71,21 +71,21 @@ public class NodeEditorGUILayout { } public static object PropertyField(string label, object value, System.Type type) { - if (type == typeof(int)) return IntField(label, value is int ? (int) value : default(int)); - else if (type == typeof(float)) return FloatField(label, value is float ? (float) value : default(float)); - else if (type == typeof(double)) return DoubleField(label, value is double ? (double) value : default(double)); - else if (type == typeof(long)) return LongField(label, value is long ? (long) value : default(long)); - else if (type == typeof(bool)) return Toggle(label, value is bool ? (bool) value : default(bool)); - else if (type == typeof(string)) return TextField(label, value is string ? (string) value : default(string)); - else if (type == typeof(Rect)) return RectField(label, value is Rect ? (Rect) value : default(Rect)); - else if (type == typeof(Vector2)) return Vector2Field(label, value is Vector2 ? (Vector2) value : default(Vector2)); - else if (type == typeof(Vector3)) return Vector3Field(label, value is Vector3 ? (Vector3) value : default(Vector3)); - else if (type == typeof(Vector4)) return Vector4Field(label, value is Vector4 ? (Vector4) value : default(Vector4)); - else if (type == typeof(Color)) return ColorField(label, value is Color ? (Color) value : default(Color)); - else if (type == typeof(AnimationCurve)) return CurveField(label, value is AnimationCurve ? (AnimationCurve) value : default(AnimationCurve)); - else if (type.IsSubclassOf(typeof(Enum)) || type == typeof(Enum)) return EnumField(label, (Enum) value); - else if (type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object)) return ObjectField(label, (UnityEngine.Object) value, type); - else return value; + if (type == typeof(int)) return IntField(label, value is int ? (int)value : default(int)); + else if (type == typeof(float)) return FloatField(label, value is float ? (float)value : default(float)); + else if (type == typeof(double)) return DoubleField(label, value is double ? (double)value : default(double)); + else if (type == typeof(long)) return LongField(label, value is long ? (long)value : default(long)); + else if (type == typeof(bool)) return Toggle(label, value is bool ? (bool)value : default(bool)); + else if (type == typeof(string)) return TextField(label, value is string ? (string)value : default(string)); + else if (type == typeof(Rect)) return RectField(label, value is Rect ? (Rect)value : default(Rect)); + else if (type == typeof(Vector2)) return Vector2Field(label, value is Vector2 ? (Vector2)value : default(Vector2)); + else if (type == typeof(Vector3)) return Vector3Field(label, value is Vector3 ? (Vector3)value : default(Vector3)); + else if (type == typeof(Vector4)) return Vector4Field(label, value is Vector4 ? (Vector4)value : default(Vector4)); + else if (type == typeof(Color)) return ColorField(label, value is Color ? (Color)value : default(Color)); + else if (type == typeof(AnimationCurve)) return CurveField(label, value is AnimationCurve ? (AnimationCurve)value : default(AnimationCurve)); + else if (type.IsSubclassOf(typeof(Enum)) || type == typeof(Enum)) return EnumField(label, (Enum)value); + else if (type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object)) return ObjectField(label, (UnityEngine.Object)value, type); + else { GUILayout.Label(label); return value; } } public static Rect GetRect(string label) { Rect rect = EditorGUILayout.GetControlRect();