#if UNITY_EDITOR using System; using UnityEngine; using UnityEditor; namespace Jovian.Utilities { public static class InspectorGUIUtility { public static object DrawField(string name, Type type, object value) { GUIContent label = new(name, $"<{type.Name}> = {value}"); if(type == typeof(string)) { return EditorGUILayout.TextField(label, (string)value); } if(type == typeof(bool)) { return EditorGUILayout.Toggle(label, (bool)value); } if(type == typeof(float)) { return EditorGUILayout.FloatField(label, (float)value); } if(type == typeof(int)) { return EditorGUILayout.IntField(label, (int)value); } if(type == typeof(byte)) { return (byte)EditorGUILayout.IntField(label, (byte)value); } if(type == typeof(Vector2)) { return EditorGUILayout.Vector2Field(label, (Vector2)value); } if(type == typeof(Vector3)) { return EditorGUILayout.Vector3Field(label, (Vector3)value); } if(type == typeof(Vector4)) { return EditorGUILayout.Vector4Field(label, (Vector4)value); } if(type == typeof(Bounds)) { return EditorGUILayout.BoundsField(label, (Bounds)value); } if(type == typeof(BoundsInt)) { return EditorGUILayout.BoundsIntField(label, (BoundsInt)value); } if(type == typeof(Color)) { return EditorGUILayout.ColorField(label, (Color)value); } if(type == typeof(AnimationCurve)) { return EditorGUILayout.CurveField(label, (AnimationCurve)value); } if (type == typeof(double)) { return EditorGUILayout.DoubleField(label, (double)value); } if (type == typeof(Gradient)) { return EditorGUILayout.GradientField(label, (Gradient)value); } if (type == typeof(long)) { return EditorGUILayout.LongField(label, (long)value); } if(type.IsEnum) { return EditorGUILayout.EnumPopup(label, (Enum)value); } if(type.IsSubclassOf(typeof(UnityEngine.Object)) || value is UnityEngine.Object) { return EditorGUILayout.ObjectField(label, (UnityEngine.Object)value, type, true); } string stringValue = value == null ? "" : value.ToString(); EditorGUILayout.TextField(label, stringValue); return value; } } } #endif