Example #1
0
    public override void OnGUI(Rect position_, SerializedProperty property_, GUIContent label_)
    {
        label_ = EditorGUI.BeginProperty(position_, label_, property_);

        if (property_.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property_.vector2Value;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            range.x = Mathf.Max(range.x, attr.min);
            range.y = Mathf.Min(range.y, attr.max);

            range = EditorGUI.Vector2Field(position_, label_, range);

            Rect position = EditorGUI.IndentedRect(position_);
            position.y     += _control_height * 1.5f;
            position.height = _control_height + 5;
            EditorGUI.MinMaxSlider(position, ref range.x, ref range.y, attr.min, attr.max);

            property_.vector2Value = range;
        }
        else
        {
            EditorGUI.LabelField(position_, label_, "Use only with Vector2");
        }

        EditorGUI.EndProperty( );
    }
Example #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MinMaxSliderAttribute minMaxSliderAttribute = (attribute as MinMaxSliderAttribute);

            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal();

            float   min   = minMaxSliderAttribute.min;
            float   max   = minMaxSliderAttribute.max;
            Vector2 value = property.vector2Value;

            Rect rect = position;

            rect.width = minMaxSliderAttribute.fieldWidth;
            value.x    = Mathf.Clamp(EditorGUI.FloatField(rect, value.x), min, value.y);

            rect.x    += rect.width + 5;
            rect.width = position.width - minMaxSliderAttribute.fieldWidth * 2 - 10;
            EditorGUI.MinMaxSlider(rect, ref value.x, ref value.y, min, max);

            rect.x    += rect.width + 5;
            rect.width = minMaxSliderAttribute.fieldWidth;
            value.y    = Mathf.Clamp(EditorGUI.FloatField(rect, value.y), value.x, max);

            property.vector2Value = value;

            GUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
            property.serializedObject.Update();
        }
Example #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.min, attr.max);
            EditorGUI.LabelField(new Rect(position.x + position.width - 200, position.y + 15, 200, 15), min.ToString());
            EditorGUI.LabelField(new Rect(position.x + position.width - 60, position.y + 15, 60, 15), max.ToString());

            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            label = EditorGUI.BeginProperty(position, label, property);

            Rect labelRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(labelRect, label);

            position.y      += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            position.height -= EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

            EditorGUI.indentLevel++;
            position = EditorGUI.IndentedRect(position);
            EditorGUI.indentLevel--;

            Rect minRect    = new Rect(position.x, position.y, 60, position.height);
            Rect sliderRect = new Rect(minRect.xMax, position.y, position.width - minRect.width * 2, position.height);
            Rect maxRect    = new Rect(sliderRect.xMax, position.y, minRect.width, position.height);

            EditorGUI.BeginChangeCheck();

            switch (property.propertyType)
            {
            case SerializedPropertyType.Vector2:
                Vector2 vec2 = property.vector2Value;
                vec2.x = EditorGUI.FloatField(minRect, vec2.x);
                EditorGUI.MinMaxSlider(sliderRect, ref vec2.x, ref vec2.y, attr.Min, attr.Max);
                vec2.y = EditorGUI.FloatField(maxRect, vec2.y);

                if (EditorGUI.EndChangeCheck())
                {
                    property.vector2Value = vec2;
                }
                break;

            case SerializedPropertyType.Vector2Int:
                Vector2 veci2 = property.vector2IntValue;
                veci2.x = EditorGUI.IntField(minRect, (int)veci2.x);
                EditorGUI.MinMaxSlider(sliderRect, ref veci2.x, ref veci2.y, (int)attr.Min, (int)attr.Max);
                veci2.y = EditorGUI.IntField(maxRect, (int)veci2.y);

                if (EditorGUI.EndChangeCheck())
                {
                    property.vector2IntValue = new Vector2Int((int)veci2.x, (int)veci2.y);
                }
                break;

            default:
                Color color = GUI.contentColor;
                GUI.contentColor = Color.red;
                EditorGUI.LabelField(position, "Unsupported field type.");
                GUI.contentColor = color;
                EditorGUI.EndChangeCheck();
                break;
            }

            EditorGUI.EndProperty();
        }
Example #5
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            float spacing = kSpacing * EditorGUIUtility.pixelsPerPoint;

            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;

            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            EditorGUI.PrefixLabel(position, label);

            Rect sliderPos = position;
            sliderPos.x     += EditorGUIUtility.labelWidth + kFloatFieldWidth + spacing;
            sliderPos.width -= EditorGUIUtility.labelWidth + (kFloatFieldWidth + spacing) * 2;

            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(sliderPos, ref min, ref max, attr.min, attr.max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }

            Rect minPos = position;
            minPos.x    += EditorGUIUtility.labelWidth;
            minPos.width = kFloatFieldWidth;

            EditorGUI.showMixedValue = property.FindPropertyRelative(kVectorMinName).hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            min = EditorGUI.FloatField(minPos, min);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = Mathf.Max(min, attr.min);
                property.vector2Value = range;
            }

            Rect maxPos = position;
            maxPos.x    += maxPos.width - kFloatFieldWidth;
            maxPos.width = kFloatFieldWidth;

            EditorGUI.showMixedValue = property.FindPropertyRelative(kVectorMaxName).hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            max = EditorGUI.FloatField(maxPos, max);
            if (EditorGUI.EndChangeCheck())
            {
                range.y = Mathf.Min(max, attr.max);
                property.vector2Value = range;
            }

            EditorGUI.showMixedValue = false;
        }
        else
        {
            EditorGUI.LabelField(position, label, new GUIContent("Vector2 support only"));
        }
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = (MinMaxSliderAttribute)attribute;
            EditorGUI.BeginChangeCheck();

            Rect   context = EditorGUI.PrefixLabel(position, label);
            Rect[] cols    = context.SplitLeft(50f);
            min  = EditorGUI.DelayedFloatField(cols[0], min);
            cols = cols[1].SplitRight(50f);
            EditorGUI.MinMaxSlider(cols[0], ref min, ref max, attr.min, attr.max);
            max = EditorGUI.DelayedFloatField(cols[1], max);

            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
Example #7
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        position.height = 30;
        EditorGUI.BeginProperty(position, label, property);

        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.min, attr.max);

            //EditorGUILayout.HelpBox ("Min: " + min + " Max: " + max, MessageType.None);

            GUIStyle style = new GUIStyle();
            style.alignment = TextAnchor.MiddleCenter;
            position.y     += 7.5f;
            EditorGUI.LabelField(position, "Min: " + min.ToString("F2") + "     Max: " + max.ToString("F2"), style);

            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }

        EditorGUI.EndProperty();
    }
Example #8
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        bool _guiEnabled           = GUI.enabled;
        MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

        if (CheckDifferent(property, attr.varToCheckHideDiferent, attr.value))
        {
            GUI.enabled = false;
        }

        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;

            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.min, attr.max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }

        GUI.enabled = _guiEnabled;
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
            EditorGUI.BeginChangeCheck();
#if UNITY_5_5_OR_NEWER
            EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.min, attr.max);
#else
            EditorGUI.MinMaxSlider(label, position, ref min, ref max, attr.min, attr.max);
#endif
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
Example #10
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();
            EditorGUI.MinMaxSlider(label, new Rect(position.x, position.y, position.width - 106, position.height), ref min, ref max, attr.min, attr.max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
            EditorGUI.TextField(new Rect(position.x + position.width - 50, position.y, 50, position.height), range.y.ToString("0.00"));
            EditorGUI.TextField(new Rect(position.x + position.width - 102, position.y, 50, position.height), range.x.ToString("0.00"));
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
            EditorGUI.BeginChangeCheck();
            float horizontalSpace = 10; // in pixel
            float floatFieldWidth = 50; // in pixel
            Rect  sliderPos       = new Rect(position.position, new Vector2(position.width - horizontalSpace * 2 - floatFieldWidth * 2, position.height));
            Rect  valueMinPos     = new Rect(new Vector2(sliderPos.xMax + horizontalSpace, position.yMin), new Vector2(floatFieldWidth, position.height));
            Rect  valueMaxPos     = new Rect(new Vector2(valueMinPos.xMax + horizontalSpace, position.yMin), new Vector2(floatFieldWidth, position.height));

            EditorGUI.MinMaxSlider(sliderPos, label, ref min, ref max, attr.min, attr.max);
            min = EditorGUI.FloatField(valueMinPos, min);
            max = EditorGUI.FloatField(valueMaxPos, max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
Example #12
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            // Draw MinMax Slider
            EditorGUI.BeginChangeCheck();
            Rect rect = new Rect(position.x, position.y, position.width, position.height / 2f);
            EditorGUI.MinMaxSlider(rect, label, ref min, ref max, attr.min, attr.max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }


            // Draw Float/Int Field
            EditorGUI.BeginChangeCheck();

            GUIContent[] sub_labels = new GUIContent[] { new GUIContent(">"), new GUIContent("<") };
            Rect         sub_rect   = new Rect(position.x, position.y + position.height / 2f, position.width, position.height / 2f);

            if (attr.hasInt)
            {
                int[] sub_ranges = new int[] { (int)min, (int)max };
                EditorGUI.MultiIntField(sub_rect, sub_labels, sub_ranges);
                if (EditorGUI.EndChangeCheck())
                {
                    range.x = (int)Mathf.Clamp(sub_ranges[0], attr.min, attr.max);
                    range.y = (int)Mathf.Clamp(sub_ranges[1], attr.min, attr.max);
                    property.vector2Value = range;
                }
            }
            else
            {
                float[] sub_ranges = new float[] { min, max };
                EditorGUI.MultiFloatField(sub_rect, sub_labels, sub_ranges);
                if (EditorGUI.EndChangeCheck())
                {
                    range.x = Mathf.Clamp(sub_ranges[0], attr.min, attr.max);
                    range.y = Mathf.Clamp(sub_ranges[1], attr.min, attr.max);
                    property.vector2Value = range;
                }
            }



            //EditorGUI.EndProperty();
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //Getting the minMax Attribute
        MinMaxSliderAttribute minMaxAttribute = (MinMaxSliderAttribute)attribute;

        //PrefixLabel returns the rect of the right part, without the label part
        Rect controlRect = EditorGUI.PrefixLabel(position, label);

        int  space = 5;                                                                                                       //Space between the rects
        Rect left  = new Rect(controlRect.x, controlRect.y, controlRect.width / 8 - space, controlRect.height);               //Rectangle for the first float value
        Rect right = new Rect(controlRect.x + controlRect.width - left.width, controlRect.y, left.width, controlRect.height); //Rectangle for the second float value
        Rect mid   = new Rect(left.xMax + space, controlRect.y, right.x - (left.xMax + space) - space, controlRect.height);   //Rectangle for the slider

        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            //Start checking if values got changed
            EditorGUI.BeginChangeCheck();

            //Vector of the values
            Vector2 vector = property.vector2Value;

            float minVal = vector.x;
            float maxVal = vector.y;

            //F2 limits the float to two decimal places
            minVal = EditorGUI.FloatField(left, float.Parse(minVal.ToString("F2")));
            maxVal = EditorGUI.FloatField(right, float.Parse(maxVal.ToString("F2")));

            //Creating the Min Max Slider
            EditorGUI.MinMaxSlider(mid, ref minVal, ref maxVal,
                                   minMaxAttribute.min, minMaxAttribute.max);

            //Clamping the values between the range
            if (minVal < minMaxAttribute.min)
            {
                minVal = minMaxAttribute.min;
            }

            if (maxVal > minMaxAttribute.max)
            {
                maxVal = minMaxAttribute.max;
            }

            //Swapping min and max if min>max
            if (minVal > maxVal)
            {
                float tmp = minVal;
                minVal = maxVal;
                maxVal = tmp;
            }

            //If the change is completed return the new vector2
            if (EditorGUI.EndChangeCheck())
            {
                property.vector2Value = new Vector2(minVal, maxVal);
            }
        }
    }
Example #14
0
        private void Draw(Rect rect, SerializedProperty property, MinMaxSliderAttribute attribute, GUIContent label = null)
        {
            var labelWidth      = EditorGUIUtility.labelWidth;
            var floatFieldWidth = EditorGUIUtility.fieldWidth;
            var sliderWidth     = rect.width - labelWidth - 2f * floatFieldWidth;
            var sliderPadding   = 5f;

            var labelRect = new Rect(
                rect.x,
                rect.y,
                labelWidth,
                rect.height);

            var sliderRect = new Rect(
                rect.x + labelWidth + floatFieldWidth + sliderPadding,
                rect.y,
                sliderWidth - 2f * sliderPadding,
                rect.height);

            var minFloatFieldRect = new Rect(
                rect.x + labelWidth,
                rect.y,
                floatFieldWidth,
                rect.height);

            var maxFloatFieldRect = new Rect(
                rect.x + labelWidth + floatFieldWidth + sliderWidth,
                rect.y,
                floatFieldWidth,
                rect.height);

            // Draw the label
            DrawLabel(ref labelRect, property, attribute, label);

            // Draw the slider
            EditorGUI.BeginChangeCheck();

            var sliderValue = property.vector2Value;

            EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, attribute.MinValue,
                                   attribute.MaxValue);

            sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x);
            sliderValue.x = Mathf.Clamp(sliderValue.x, attribute.MinValue,
                                        Mathf.Min(attribute.MaxValue, sliderValue.y));

            sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y);
            sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(attribute.MinValue, sliderValue.x),
                                        attribute.MaxValue);

            if (EditorGUI.EndChangeCheck())
            {
                property.vector2Value = sliderValue;
            }
        }
Example #15
0
 private void DrawSlider(SerializedProperty property, MinMaxSliderAttribute attribute, GUIContent label = null)
 {
     if (property.propertyType == SerializedPropertyType.Vector2)
     {
         Draw(EditorGUILayout.GetControlRect(), property, attribute, label);
     }
     else
     {
         EditorDrawUtility.DrawPropertyField(property, label);
         EditorDrawUtility.DrawHelpBox($"{typeof(MinMaxSliderAttribute).Name} can be used only on Vector2 fields");
     }
 }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            const float dataWidth = 60;
            const float spacing   = 5;

            Rect leftHandSide = position;
            leftHandSide.max = leftHandSide.max - Vector2.right * (dataWidth * 2 + spacing * 2);

            EditorGUI.BeginChangeCheck();

            EditorGUI.MinMaxSlider(leftHandSide, label, ref min, ref max, attr.min, attr.max);

            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }


            Rect minRegion = new Rect(leftHandSide.xMax + spacing, leftHandSide.y, dataWidth, leftHandSide.height);
            Rect maxRegion = new Rect(minRegion.xMax + spacing, leftHandSide.y, dataWidth, leftHandSide.height);

            EditorGUI.BeginChangeCheck();

            float labelWidth = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = 0;
            min = EditorGUI.FloatField(minRegion, min);
            max = EditorGUI.FloatField(maxRegion, max);
            EditorGUIUtility.labelWidth = labelWidth;
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
        EditorGUI.EndProperty();
    }
Example #17
0
 private void DrawSlider(Rect position, SerializedProperty property, MinMaxSliderAttribute attribute)
 {
     if (property.propertyType == SerializedPropertyType.Vector2)
     {
         Draw(position, property, attribute);
     }
     else
     {
         EditorDrawUtility.DrawPropertyField(position, property);
         position.y      += 18;
         position.height -= 26;
         EditorDrawUtility.DrawHelpBox(position, $"{typeof(MinMaxSliderAttribute).Name} can be used only on Vector2 fields");
     }
 }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            float componentHeight = 16.0f;
            float verticalPadding = 2.0f;

            label = EditorGUI.BeginProperty(position, label, property);

            Rect sliderRect = new Rect(position.x,
                                       position.y,
                                       position.width,
                                       componentHeight);

            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(sliderRect, label, ref min, ref max, attr.min, attr.max);

            Rect lower = EditorGUI.PrefixLabel(sliderRect, label);
            lower.y     += componentHeight + verticalPadding;
            lower.width /= 2;

            Rect upper = new Rect(lower.x + lower.width,
                                  lower.y,
                                  lower.width,
                                  componentHeight);

            EditorGUIUtility.labelWidth = 35f;
            min = EditorGUI.FloatField(lower, "From", min);
            EditorGUIUtility.labelWidth = 20f;
            max = EditorGUI.FloatField(upper, "To", max);

            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }

            EditorGUI.EndProperty();
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
Example #19
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                position.width -= 5;
                float textFieldWidth = 50;

                position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

                var v_indentLevel = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 0;
                Vector2 range = property.vector2Value;
                float   min   = range.x;
                float   max   = range.y;
                MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

                EditorGUI.BeginChangeCheck();
                Rect minPos = new Rect(position);
                //minPos.x += v_labelWidth;
                minPos.width = textFieldWidth;
                min          = EditorGUI.FloatField(minPos, min);

                var  v_padding = 5;
                Rect sliderPos = new Rect(position);
                sliderPos.width -= (textFieldWidth * 2) + (v_padding);
                sliderPos.x     += v_padding + textFieldWidth;

                EditorGUI.MinMaxSlider(sliderPos, ref min, ref max, attr.min, attr.max);

                Rect maxPos = new Rect(sliderPos.xMax + v_padding, sliderPos.y, textFieldWidth, sliderPos.height);
                max = EditorGUI.FloatField(maxPos, max);

                if (min > max)
                {
                    min = max;
                }
                if (EditorGUI.EndChangeCheck())
                {
                    range.x = min;
                    range.y = max;
                    property.vector2Value = range;
                }
                EditorGUI.indentLevel = v_indentLevel;
            }
            else
            {
                EditorGUI.LabelField(position, label, "Use only with Vector2");
            }
        }
        public void DrawDirectly(SerializedProperty property, CyberAttrribute cyberAttribute, GUIContent content, GUIStyle style, FieldInfo field)
        {
            MinMaxSliderAttribute atr = cyberAttribute as MinMaxSliderAttribute;

            EditorGUILayout.BeginHorizontal();
            TheEditor.DrawPrefix(content, field, style);
            float min, max;
            SerializedProperty pVect = null;

            if (property.propertyType == SerializedPropertyType.Generic)
            {
                pVect = property.FindPropertyRelative("val");

                min = pVect.vector2Value.x;
                max = pVect.vector2Value.y;
            }


            else if (property.propertyType == SerializedPropertyType.Vector2)
            {
                min = property.vector2Value.x;
                max = property.vector2Value.y;
            }
            else
            {
                min = property.vector2IntValue.x;
                max = property.vector2IntValue.y;
            }


            min = EditorGUILayout.FloatField(min, GUILayout.MinWidth(15), GUILayout.MaxWidth(70));
            EditorGUILayout.MinMaxSlider(ref min, ref max, atr.Min, atr.Max);
            max = EditorGUILayout.FloatField(max, GUILayout.MinWidth(15), GUILayout.MaxWidth(70));
            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                property.vector2Value = new Vector2(min, max);
            }
            else if (property.propertyType == SerializedPropertyType.Vector2Int)
            {
                property.vector2IntValue = new Vector2Int((int)min, (int)max);
            }
            else if (property.propertyType == SerializedPropertyType.Generic)
            {
                pVect.vector2Value = new Vector2(min, max);
            }
            EditorGUILayout.EndHorizontal();
        }
Example #21
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MinMaxSliderAttribute minMaxAttribute = (MinMaxSliderAttribute)attribute;

            // Check for float
            if (property.propertyType == SerializedPropertyType.Float)
            {
                string maxVariableName = minMaxAttribute.MaxVariableName;
                if (FindMaxProperty(property, maxVariableName, SerializedPropertyType.Float, out SerializedProperty maxProperty, out string warning))
                {
                    MMSEditorGUI.MinMaxSlider(position, minMaxAttribute.DisplayName ?? property.displayName, property, maxProperty, minMaxAttribute.Min, minMaxAttribute.Max, minMaxAttribute.MinFieldPosition, minMaxAttribute.MaxFieldPosition);
                }
                else
                {
                    EditorGUI.LabelField(position, EditorGUIUtility.TrTextContent(minMaxAttribute.DisplayName ?? property.displayName, warning), EditorGUIUtility.TrTempContent(warning));
                }
            }
Example #22
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     if (property.propertyType == SerializedPropertyType.Vector2)
     {
         Vector2 range = property.vector2Value;
         float   min   = range.x;
         float   max   = range.y;
         MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
         EditorGUI.BeginChangeCheck();
         EditorGUI.MinMaxSlider(label, position, ref min, ref max, attr.min, attr.max);
         position.y += 15;
         position.x += 150;
         EditorGUI.LabelField(position, "Min:" + min.ToString() + " Max:" + max.ToString());
         if (EditorGUI.EndChangeCheck())
         {
             range.x = min;
             range.y = max;
             property.vector2Value = range;
         }
     }
 }
Example #23
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            float textFieldWidth = 30;

            EditorGUI.LabelField(position, label);
            Vector2 range = property.vector2Value;
            float   min   = range.x;
            float   max   = range.y;
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

            Rect sliderPos = position;
            sliderPos.x     += EditorGUIUtility.labelWidth + textFieldWidth;
            sliderPos.width -= EditorGUIUtility.labelWidth + textFieldWidth * 2;
            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(sliderPos, ref min, ref max, attr.min, attr.max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
            EditorGUI.LabelField(position, "");

            Rect minPos = position;
            minPos.x    += EditorGUIUtility.labelWidth;
            minPos.width = textFieldWidth;
            EditorGUI.LabelField(minPos, min.ToString("0.00"));
            Rect maxPos = position;
            maxPos.x    += maxPos.width - textFieldWidth;
            maxPos.width = textFieldWidth;
            EditorGUI.LabelField(maxPos, max.ToString("0.00"));
        }
        else
        {
            EditorGUI.LabelField(position, label, "Use only with Vector2");
        }
    }
Example #24
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     if (property.propertyType == SerializedPropertyType.Vector2)
     {
         Vector2 range = property.vector2Value;
         float   min   = range.x;
         float   max   = range.y;
         MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
         EditorGUI.BeginChangeCheck();
         // EditorGUI.LabelField(position, System.Math.Round(range.x, 2).ToString());
         EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.min, attr.max);
         // EditorGUI.LabelField(position, System.Math.Round(range.y, 2).ToString());
         if (EditorGUI.EndChangeCheck())
         {
             range.x = min;
             range.y = max;
             property.vector2Value = range;
         }
     }
     else
     {
         EditorGUI.LabelField(position, label, "Use only with Vector2");
     }
 }
Example #25
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     if (property.propertyType == SerializedPropertyType.Vector2)
     {
         Vector2 range = property.vector2Value;
         float   min   = range.x;
         float   max   = range.y;
         MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
         EditorGUI.BeginChangeCheck();
         label.text += (" " + min.ToString("#.0") + "-" + max.ToString("#.0"));
         EditorGUI.MinMaxSlider(label, position, ref min, ref max, attr.min, attr.max);
         //EditorGUI.LabelField(position, (min +":"+ max) );
         if (EditorGUI.EndChangeCheck())
         {
             range.x = min;
             range.y = max;
             property.vector2Value = range;
         }
     }
     else
     {
         EditorGUI.LabelField(position, label, "Use only with Vector2");
     }
 }
Example #26
0
        protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(rect, label, property);

            MinMaxSliderAttribute minMaxSliderAttribute = (MinMaxSliderAttribute)attribute;

            if (property.propertyType == SerializedPropertyType.Vector2 || property.propertyType == SerializedPropertyType.Vector2Int)
            {
                EditorGUI.BeginProperty(rect, label, property);

                float indentLength    = NaughtyEditorGUI.GetIndentLength(rect);
                float labelWidth      = EditorGUIUtility.labelWidth + NaughtyEditorGUI.HorizontalSpacing;
                float floatFieldWidth = EditorGUIUtility.fieldWidth;
                float sliderWidth     = rect.width - labelWidth - 2.0f * floatFieldWidth;
                float sliderPadding   = 5.0f;

                Rect labelRect = new Rect(
                    rect.x,
                    rect.y,
                    labelWidth,
                    rect.height);

                Rect sliderRect = new Rect(
                    rect.x + labelWidth + floatFieldWidth + sliderPadding - indentLength,
                    rect.y,
                    sliderWidth - 2.0f * sliderPadding + indentLength,
                    rect.height);

                Rect minFloatFieldRect = new Rect(
                    rect.x + labelWidth - indentLength,
                    rect.y,
                    floatFieldWidth + indentLength,
                    rect.height);

                Rect maxFloatFieldRect = new Rect(
                    rect.x + labelWidth + floatFieldWidth + sliderWidth - indentLength,
                    rect.y,
                    floatFieldWidth + indentLength,
                    rect.height);

                // Draw the label
                EditorGUI.LabelField(labelRect, label.text);

                // Draw the slider
                EditorGUI.BeginChangeCheck();

                if (property.propertyType == SerializedPropertyType.Vector2)
                {
                    Vector2 sliderValue = property.vector2Value;
                    EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue);

                    sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x);
                    sliderValue.x = Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y));

                    sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y);
                    sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue);

                    if (EditorGUI.EndChangeCheck())
                    {
                        property.vector2Value = sliderValue;
                    }
                }
                else if (property.propertyType == SerializedPropertyType.Vector2Int)
                {
                    Vector2Int sliderValue = property.vector2IntValue;
                    float      xValue      = sliderValue.x;
                    float      yValue      = sliderValue.y;
                    EditorGUI.MinMaxSlider(sliderRect, ref xValue, ref yValue, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue);

                    sliderValue.x = EditorGUI.IntField(minFloatFieldRect, (int)xValue);
                    sliderValue.x = (int)Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y));

                    sliderValue.y = EditorGUI.IntField(maxFloatFieldRect, (int)yValue);
                    sliderValue.y = (int)Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue);

                    if (EditorGUI.EndChangeCheck())
                    {
                        property.vector2IntValue = sliderValue;
                    }
                }

                EditorGUI.EndProperty();
            }
            else
            {
                string message = minMaxSliderAttribute.GetType().Name + " can be used only on Vector2 or Vector2Int fields";
                DrawDefaultPropertyAndHelpBox(rect, property, message, MessageType.Warning);
            }

            EditorGUI.EndProperty();
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        bool isVector2    = property.propertyType == SerializedPropertyType.Vector2;
        bool isVector2Int = property.propertyType == SerializedPropertyType.Vector2Int;

        if (isVector2 || isVector2Int)
        {
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
            float minLimit             = 0;
            float maxLimit             = 0;
            if (string.IsNullOrEmpty(attr.limitField) && (string.IsNullOrEmpty(attr.minLimitField) || string.IsNullOrEmpty(attr.maxLimitField)))
            {
                minLimit = attr.minLimit;
                maxLimit = attr.maxLimit;
            }
            else if (!string.IsNullOrEmpty(attr.limitField))
            {
                if (property.serializedObject == null || !property.serializedObject.targetObject)
                {
                    EditorGUI.PropertyField(position, property, label, true);
                    return;
                }
                SerializedProperty limitField = property.serializedObject.FindProperty(attr.limitField);
                if (limitField != null)
                {
                    if (limitField.propertyType == SerializedPropertyType.Vector2)
                    {
                        minLimit = limitField.vector2Value.x;
                        maxLimit = limitField.vector2Value.y;
                    }
                    else if (limitField.propertyType == SerializedPropertyType.Vector2Int)
                    {
                        minLimit = limitField.vector2IntValue.x;
                        maxLimit = limitField.vector2IntValue.y;
                    }
                    else
                    {
                        EditorGUI.PropertyField(position, property, label, true);
                        return;
                    }
                }
                else
                {
                    EditorGUI.PropertyField(position, property, label, true);
                    return;
                }
            }
            else if (!string.IsNullOrEmpty(attr.minLimitField) && !string.IsNullOrEmpty(attr.maxLimitField))
            {
                if (property.serializedObject == null || !property.serializedObject.targetObject)
                {
                    EditorGUI.PropertyField(position, property, label, true);
                    return;
                }
                SerializedProperty minLimitField = property.serializedObject.FindProperty(attr.minLimitField);
                SerializedProperty maxLimitField = property.serializedObject.FindProperty(attr.maxLimitField);
                if (minLimitField != null && maxLimitField != null)
                {
                    if (minLimitField.propertyType == SerializedPropertyType.Float)
                    {
                        minLimit = minLimitField.floatValue;
                    }
                    else if (minLimitField.propertyType == SerializedPropertyType.Integer)
                    {
                        minLimit = minLimitField.intValue;
                    }
                    else
                    {
                        EditorGUI.PropertyField(position, property, label, true);
                        return;
                    }
                    if (maxLimitField.propertyType == SerializedPropertyType.Float)
                    {
                        maxLimit = maxLimitField.floatValue;
                    }
                    else if (maxLimitField.propertyType == SerializedPropertyType.Integer)
                    {
                        maxLimit = maxLimitField.intValue;
                    }
                    else
                    {
                        EditorGUI.PropertyField(position, property, label, true);
                        return;
                    }
                }
                else
                {
                    EditorGUI.PropertyField(position, property, label, true);
                    return;
                }
            }
            float minValue = isVector2 ? property.vector2Value.x : property.vector2IntValue.x;
            float maxValue = isVector2 ? property.vector2Value.y : property.vector2IntValue.y;
            label = EditorGUI.BeginProperty(position, label, property);
            EditorGUI.LabelField(new Rect(position.x, position.y, EditorGUIUtility.labelWidth, position.height), label);
            minValue = EditorGUI.FloatField(new Rect(position.x + EditorGUIUtility.labelWidth + 2, position.y, 40, position.height), minValue);
            if (minValue < minLimit)
            {
                minValue = minLimit;
            }
            maxValue = EditorGUI.FloatField(new Rect(position.x + position.width - 40, position.y, 40, position.height), maxValue);
            if (maxValue > maxLimit)
            {
                maxValue = maxLimit;
            }
            EditorGUI.MinMaxSlider(new Rect(position.x + EditorGUIUtility.labelWidth + 45, position.y, position.width - EditorGUIUtility.labelWidth - 88, position.height), ref minValue, ref maxValue, minLimit, maxLimit);
            if (isVector2)
            {
                property.vector2Value = new Vector2(minValue, maxValue);
            }
            else
            {
                property.vector2IntValue = new Vector2Int(Mathf.FloorToInt(minValue), Mathf.FloorToInt(maxValue));
            }
            EditorGUI.EndProperty();
        }
    }
        public override void DrawProperty(SerializedProperty property)
        {
            EditorDrawUtility.DrawHeader(property);

            MinMaxSliderAttribute minMaxSliderAttribute = PropertyUtility.GetAttribute <MinMaxSliderAttribute>(property);

            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                Rect  controlRect     = EditorGUILayout.GetControlRect();
                float labelWidth      = EditorGUIUtility.labelWidth;
                float floatFieldWidth = EditorGUIUtility.fieldWidth;
                float sliderWidth     = controlRect.width - labelWidth - 2f * floatFieldWidth;
                float sliderPadding   = 5f;

                Rect labelRect = new Rect(
                    controlRect.x,
                    controlRect.y,
                    labelWidth,
                    controlRect.height);

                Rect sliderRect = new Rect(
                    controlRect.x + labelWidth + floatFieldWidth + sliderPadding,
                    controlRect.y,
                    sliderWidth - 2f * sliderPadding,
                    controlRect.height);

                Rect minFloatFieldRect = new Rect(
                    controlRect.x + labelWidth,
                    controlRect.y,
                    floatFieldWidth,
                    controlRect.height);

                Rect maxFloatFieldRect = new Rect(
                    controlRect.x + labelWidth + floatFieldWidth + sliderWidth,
                    controlRect.y,
                    floatFieldWidth,
                    controlRect.height);

                // Draw the label
                EditorGUI.LabelField(labelRect, property.displayName);

                // Draw the slider
                EditorGUI.BeginChangeCheck();

                Vector2 sliderValue = property.vector2Value;
                EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue);

                sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x);
                sliderValue.x = Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y));

                sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y);
                sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue);

                if (EditorGUI.EndChangeCheck())
                {
                    property.vector2Value = sliderValue;
                }
            }
            else
            {
                string warning = minMaxSliderAttribute.GetType().Name + " can be used only on Vector2 fields";
                EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property));

                EditorDrawUtility.DrawPropertyField(property);
            }
        }
Example #29
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2 || property.type == typeof(Range).Name)
        {
            float min;
            float max;
            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                min = property.vector2Value.x;
                max = property.vector2Value.y;
            }
            else
            {
                min = property.FindPropertyRelative("Min").floatValue;
                max = property.FindPropertyRelative("Max").floatValue;
            }
            MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
            label.tooltip = string.Format("{0}, {1}", min, max);
            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.Min, attr.Max);

            if (attr.Step > 0f)
            {
                min -= (min % attr.Step);
                max -= (max % attr.Step);
            }

            position.xMin += EditorGUIUtility.labelWidth;
            position.yMin += EditorGUIUtility.singleLineHeight - EditorGUIUtility.standardVerticalSpacing;

            var fullWidth = position.width;
            var span      = attr.Max - attr.Min;
            var minPos    = fullWidth * (min - attr.Min) / span;
            var maxPos    = fullWidth * (max - attr.Min) / span;

            position.xMin += minPos;
            position.width = maxPos - minPos;

            var style = new GUIStyle(EditorStyles.miniLabel);
            style.alignment = TextAnchor.UpperLeft;
            EditorGUI.LabelField(position, min.ToString("0.00"), style);
            style.alignment = TextAnchor.UpperRight;
            EditorGUI.LabelField(position, max.ToString("0.00"), style);

            if (EditorGUI.EndChangeCheck())
            {
                if (property.propertyType == SerializedPropertyType.Vector2)
                {
                    property.vector2Value = new Vector2(min, max);
                }
                else
                {
                    property.FindPropertyRelative("Min").floatValue = Mathf.RoundToInt(min);
                    property.FindPropertyRelative("Max").floatValue = Mathf.RoundToInt(max);
                }
            }
        }
        else
        {
            EditorGUI.HelpBox(position, "Use MinMaxSlider only with type Vector2 or Range.", MessageType.Warning);
        }
    }
Example #30
0
    //float _previousFieldWidth;

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        _rectPosition = position;

        if (property.propertyType != SerializedPropertyType.Vector2)
        {
            EditorGUI.LabelField(position, label, "MinMaxSlider only works with Vector2");
            return;
        }

        Vector2 range = property.vector2Value;
        float   min   = range.x;
        float   max   = range.y;
        MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;

        // Draw MinMax Slider
        EditorGUI.BeginChangeCheck();
        Rect rect = new Rect(position.x, position.y, position.width, GetHeight());

        EditorGUI.MinMaxSlider(rect, label, ref min, ref max, attr.min, attr.max);
        if (EditorGUI.EndChangeCheck())
        {
            range.x = min;
            range.y = max;
            property.vector2Value = range;
        }


        // Draw Float/Int Field

        _previousLabelWidth = EditorGUIUtility.labelWidth;
        //_previousFieldWidth = EditorGUIUtility.fieldWidth;
        EditorGUIUtility.labelWidth = LABEL_WIDTH;
        //EditorGUIUtility.fieldWidth = FIELD_WIDTH;

        EditorGUI.BeginChangeCheck();

        if (attr.hasInt)
        {
            int intMin = EditorGUI.IntField(
                new Rect(GetFieldX(0), GetFieldY(1), GetFieldWidth(), GetHeight()),
                new GUIContent(LABEL_MIN), (int)min);
            int intMax = EditorGUI.IntField(
                new Rect(GetFieldX(1), GetFieldY(1), GetFieldWidth(), GetHeight()),
                new GUIContent(LABEL_MAX), (int)max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = Mathf.Clamp(intMin, attr.min, attr.max);
                range.y = Mathf.Clamp(intMax, attr.min, attr.max);
                property.vector2Value = range;
            }
        }
        else
        {
            min = EditorGUI.FloatField(
                new Rect(GetFieldX(0), GetFieldY(1), GetFieldWidth(), GetHeight()),
                new GUIContent(LABEL_MIN), min);
            max = EditorGUI.FloatField(
                new Rect(GetFieldX(1), GetFieldY(1), GetFieldWidth(), GetHeight()),
                new GUIContent(LABEL_MAX), max);
            if (EditorGUI.EndChangeCheck())
            {
                range.x = Mathf.Clamp(min, attr.min, attr.max);
                range.y = Mathf.Clamp(max, attr.min, attr.max);
                property.vector2Value = range;
            }
        }


        //EditorGUI.EndProperty();
        EditorGUIUtility.labelWidth = _previousLabelWidth;
        //EditorGUIUtility.fieldWidth = _previousFieldWidth;
    }