public static void DrawFloatTextField(this PropertyDrawer drawer, Rect position, string text, string tooltip, SerializedProperty prop)
        {
            EditorGUI.BeginChangeCheck();
            float value = EditorGUI.FloatField(position, new GUIContent(text, tooltip), prop.floatValue);
            SingleLineClampAttribute clamp = drawer.attribute as SingleLineClampAttribute;

            if (clamp != null)
            {
                value = Mathf.Clamp(value, (float)clamp.MinValue, (float)clamp.MaxValue);
            }
            if (EditorGUI.EndChangeCheck())
            {
                prop.floatValue = value;
            }
        }
Exemple #2
0
        private void DrawIntTextField(Rect position, string text, string tooltip, SerializedProperty prop)
        {
            EditorGUI.BeginChangeCheck();
            int value = EditorGUI.IntField(position, new GUIContent(text, tooltip), prop.intValue);
            SingleLineClampAttribute clamp = attribute as SingleLineClampAttribute;

            if (clamp != null)
            {
                value = Mathf.Clamp(value, (int)clamp.MinValue, (int)clamp.MaxValue);
            }
            if (EditorGUI.EndChangeCheck())
            {
                prop.intValue = value;
            }
        }
        private void RenderIntField(Rect rect, WeatherMakerPropertyTransition t, GUIContent label, FieldInfo field, RangeAttribute range, SingleLineClampAttribute clamp)
        {
            int val = (int)GetFieldValue(field, t);

            if (clamp != null)
            {
                val = Mathf.Clamp(val, (int)clamp.MinValue, (int)clamp.MaxValue);
            }
            if (range == null)
            {
                t.Value = EditorGUI.IntField(rect, label, val);
            }
            else
            {
                t.Value = EditorGUI.IntSlider(rect, label, val, (int)range.min, (int)range.max);
            }
        }
        private void RenderField(Rect rect, WeatherMakerPropertyTransition t, FieldInfo field, float textFieldWidth)
        {
            if (t == null || field == null)
            {
                return;
            }
            string                   tooltip = null;
            RangeAttribute           range   = null;
            SingleLineClampAttribute clamp   = null;

            object[] attributes = field.GetCustomAttributes(false);
            foreach (object obj in attributes)
            {
                if (obj is TooltipAttribute)
                {
                    tooltip = (obj as TooltipAttribute).tooltip;
                }
                else if (obj is SingleLineAttribute)
                {
                    tooltip = (obj as SingleLineAttribute).Tooltip;
                }
                else if (obj is RangeAttribute)
                {
                    range = obj as RangeAttribute;
                }
                else if (obj is SingleLineClampAttribute)
                {
                    clamp = obj as SingleLineClampAttribute;
                }
            }
            GUIContent label = new GUIContent("Value", tooltip);

            EditorGUIUtility.fieldWidth = 70.0f;
            if (field.FieldType == typeof(float))
            {
                RenderFloatField(rect, t, label, field, range, clamp);
            }
            else if (field.FieldType == typeof(int))
            {
                RenderIntField(rect, t, label, field, range, clamp);
            }
            else if (field.FieldType == typeof(bool))
            {
                t.Value = EditorGUI.Toggle(rect, label, (bool)GetFieldValue(field, t));
            }
            else if (field.FieldType == typeof(Color))
            {
                t.Value = EditorGUI.ColorField(rect, label, (Color)GetFieldValue(field, t));
            }
            else if (field.FieldType == typeof(Vector2))
            {
                t.Value = EditorGUI.Vector2Field(rect, label, (Vector2)GetFieldValue(field, t));
            }
            else if (field.FieldType == typeof(Vector3))
            {
                t.Value = EditorGUI.Vector3Field(rect, label, (Vector3)GetFieldValue(field, t));
            }
            else if (field.FieldType == typeof(Vector4))
            {
                t.Value = EditorGUI.Vector4Field(rect, label, (Vector4)GetFieldValue(field, t));
            }
            else if (field.FieldType == typeof(RangeOfFloats))
            {
                RenderRangeOfFloats(rect, t, field, clamp);
            }
            else if (field.FieldType == typeof(RangeOfIntegers))
            {
                RenderRangeOfInts(rect, t, field, clamp);
            }
            else if (field.FieldType.IsEnum)
            {
                t.Value = EditorGUI.EnumPopup(rect, label, (System.Enum)GetFieldValue(field, t));
            }
            else
            {
                EditorGUI.LabelField(rect, "Unsupported field type " + field.FieldType);
            }
        }
        private void RenderRangeOfInts(Rect rect, WeatherMakerPropertyTransition t, FieldInfo field, SingleLineClampAttribute clamp)
        {
            GUIContent      labelMin = new GUIContent("Min", "Minimum Value (Inclusive)");
            GUIContent      labelMax = new GUIContent("Max", "Maximum Value (Inclusive)");
            RangeOfIntegers r        = (RangeOfIntegers)GetFieldValue(field, t);
            float           w        = rect.width;

            rect.width *= 0.5f;
            rect.width -= 6.0f;
            r.Minimum   = EditorGUI.IntField(rect, labelMin, r.Minimum);
            rect.x     += rect.width + 6.0f;
            r.Maximum   = EditorGUI.IntField(rect, labelMax, r.Maximum);
            t.Value     = r;
        }
        private void RenderFloatField(Rect rect, WeatherMakerPropertyTransition t, GUIContent label, MemberInfo member, RangeAttribute range, SingleLineClampAttribute clamp)
        {
            float val = (float)GetMemberValue(member, t);

            if (clamp != null)
            {
                val = Mathf.Clamp(val, clamp.MinValue, clamp.MaxValue);
            }
            if (range == null)
            {
                t.Value = EditorGUI.FloatField(rect, label, val);
            }
            else
            {
                t.Value = EditorGUI.Slider(rect, label, val, range.min, range.max);
            }
        }