예제 #1
0
        public static object DrawFieldElementCompact(SerializedPropertyType type, object value, System.Type sysType, ShowInEditorRange range, ShowInEditorStyle style)
        {
            switch (type)
            {
            case SerializedPropertyType.Integer:
                return(DrawIntegerField("", value, sysType, range, style));

            case SerializedPropertyType.Float:
                return(DrawFloatField("", value, sysType, range, style));

            case SerializedPropertyType.Boolean:
                // for some reason, editor gui layout doesn't work here
                return(GUILayout.Toggle((bool)value, new GUIContent(""), new GUILayoutOption[] { GUILayout.Width(24) }));

            case SerializedPropertyType.String:
                return(EditorGUILayout.TextField((string)value));

            case SerializedPropertyType.Enum:
                return(EditorGUILayout.EnumPopup((System.Enum)value));

            default:
                break;
            }

            return(null);
        }
예제 #2
0
        public static float DrawFloatField(string name, object value, System.Type sysType, ShowInEditorRange range, ShowInEditorStyle style)
        {
            float fv;

            if (sysType != typeof(double))
            {
                fv = (float)value;
            }
            else
            {
                // aaaa
                double v = (double)value;
                fv = (float)v;
            }

            float rv;

            if (style != ShowInEditorStyle.Slider || range == null)
            {
                rv = EditorGUILayout.FloatField(name, fv);
                if (range != null)
                {
                    rv = Mathf.Clamp(rv, range.Min, range.Max);
                }
            }
            else
            {
                rv = EditorGUILayout.Slider(name, fv, range.Min, range.Max);
            }
            return(rv);
        }
예제 #3
0
        public static object DrawFieldElement(SerializedPropertyType type, string name, object value, System.Type sysType, ShowInEditorRange range, ShowInEditorStyle style)
        {
            switch (type)
            {
            case SerializedPropertyType.Integer:
                return(DrawIntegerField(name, value, sysType, range, style));

            case SerializedPropertyType.Float:
                return(DrawFloatField(name, value, sysType, range, style));

            case SerializedPropertyType.Boolean:
                return(EditorGUILayout.Toggle(name, (bool)value));

            case SerializedPropertyType.String:
                return(EditorGUILayout.TextField(name, (string)value));

            case SerializedPropertyType.Vector2:
                return(EditorGUILayout.Vector2Field(name, (Vector2)value));

            case SerializedPropertyType.Vector3:
                return(EditorGUILayout.Vector3Field(name, (Vector3)value));

            case SerializedPropertyType.Vector4:
                return(EditorGUILayout.Vector4Field(name, (Vector4)value));

            case SerializedPropertyType.Quaternion:
            {
                Vector4    v = EditorGUILayout.Vector4Field(name, (Vector4)value);
                Quaternion q = new Quaternion(v.x, v.y, v.z, v.w);
                return(q);
            }

            case SerializedPropertyType.Enum:
                return(EditorGUILayout.EnumPopup(name, (System.Enum)value));

            case SerializedPropertyType.Color:
                return(EditorGUILayout.ColorField(name, (Color)value));

            case SerializedPropertyType.Rect:
                return(EditorGUILayout.RectField(name, (Rect)value));

            case SerializedPropertyType.Bounds:
                return(EditorGUILayout.BoundsField(name, (Bounds)value));

            case SerializedPropertyType.Gradient:
                Gradient g = (Gradient)value;
                EditorGUILayout.LabelField(name, g.ToString());
                break;

            case SerializedPropertyType.AnimationCurve:
                return(EditorGUILayout.CurveField(name, (AnimationCurve)value));

            case SerializedPropertyType.ObjectReference:
            {
                if (typeof(UnityEngine.Object).IsAssignableFrom(sysType))
                {
                    return(EditorGUILayout.ObjectField(name, (UnityEngine.Object)value, sysType, true));
                }
            }
            break;

            default:
                break;
            }

            return(null);
        }
예제 #4
0
        public static int DrawIntegerField(string name, object value, System.Type sysType, ShowInEditorRange range, ShowInEditorStyle style)
        {
            int v;

            if (style != ShowInEditorStyle.Slider || range == null)
            {
                v = EditorGUILayout.IntField(name, (int)value);
                if (range != null)
                {
                    v = (int)Mathf.Clamp(v, range.Min, range.Max);
                }
                return(v);
            }
            else
            {
                int vv = (int)value;
                v = (int)EditorGUILayout.Slider(name, (float)vv, range.Min, range.Max);
                return(v);
            }
        }