/// <inheritdoc/> protected override float EditValue(float value, FloatRangeAttribute range, IWindowsFormsEditorService editorService) { #region Sanity checks if (editorService == null) { throw new ArgumentNullException(nameof(editorService)); } if (range == null) { throw new ArgumentNullException(nameof(range)); } #endregion // Scale up by factor 40 and clamp within [minimum,maximum] var trackBar = new TrackBar { TickFrequency = 40, Minimum = (int)(range.Minimum * 40), Maximum = (int)(range.Maximum * 40), }; trackBar.Value = ((int)(value * 40)).Clamp(trackBar.Minimum, trackBar.Maximum); editorService.DropDownControl(trackBar); return(trackBar.Value / 40f); }
/// <inheritdoc/> protected override float EditValue(float value, FloatRangeAttribute range, IWindowsFormsEditorService editorService) { #region Sanity checks if (editorService == null) throw new ArgumentNullException(nameof(editorService)); if (range == null) throw new ArgumentNullException(nameof(range)); #endregion var angleControl = new AngleControl {Angle = value, Range = range}; editorService.DropDownControl(angleControl); return angleControl.Angle; }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Now draw the property as a Slider or an IntSlider based on whether it’s a float or integer. if (property.type != typeof(FloatRange).ToString()) { Debug.LogWarning("Use only with FloatRange type"); } else { // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); // Don't make child fields be indented var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; FloatRangeAttribute range = attribute as FloatRangeAttribute; SerializedProperty minValue = property.FindPropertyRelative("RangeStart"); SerializedProperty maxValue = property.FindPropertyRelative("RangeEnd"); float fMin = minValue.floatValue; float fMax = maxValue.floatValue; // Calculate rects float space = 5; float textWidth = 30; var minRect = new Rect(position.x, position.y, textWidth, position.height); var mmRect = new Rect(minRect.x + minRect.width + space, position.y, position.width - (space + textWidth) * 2, position.height); var maxRect = new Rect(mmRect.x + mmRect.width + space, position.y, textWidth, position.height); EditorGUI.MinMaxSlider(mmRect, ref fMin, ref fMax, range.MinLimit, range.MaxLimit); fMin = EditorGUI.FloatField(minRect, fMin); fMax = EditorGUI.FloatField(maxRect, fMax); fMin = Mathf.Min(Mathf.Max(fMin, range.MinLimit), fMax, range.MaxLimit); fMax = Mathf.Max(Mathf.Min(fMax, range.MaxLimit), fMin, range.MinLimit); minValue.floatValue = fMin; maxValue.floatValue = fMax; // Set indent back to what it was EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); } }
/// <inheritdoc/> protected override float EditValue(float value, FloatRangeAttribute range, IWindowsFormsEditorService editorService) { #region Sanity checks if (editorService == null) throw new ArgumentNullException(nameof(editorService)); if (range == null) throw new ArgumentNullException(nameof(range)); #endregion // Scale up by factor 40 and clamp within [minimum,maximum] var trackBar = new TrackBar { TickFrequency = 40, Minimum = (int)(range.Minimum * 40), Maximum = (int)(range.Maximum * 40), }; trackBar.Value = ((int)(value * 40)).Clamp(trackBar.Minimum, trackBar.Maximum); editorService.DropDownControl(trackBar); return trackBar.Value / 40f; }
/// <inheritdoc/> protected override float EditValue(float value, FloatRangeAttribute range, IWindowsFormsEditorService editorService) { #region Sanity checks if (editorService == null) { throw new ArgumentNullException(nameof(editorService)); } if (range == null) { throw new ArgumentNullException(nameof(range)); } #endregion var angleControl = new AngleControl { Angle = value, Range = range }; editorService.DropDownControl(angleControl); return(angleControl.Angle); }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Now draw the property as a Slider or an IntSlider based on whether it’s a float or integer. // Если отрисовка вызвана, но тип свойста, над которым стоит этот аттрибут другой if (property.type != typeof(FloatRange).ToString()) { Debug.LogWarning("Use only with IntRange type"); } else { // Получаем атрибут текущего свойства FloatRangeAttribute range = attribute as FloatRangeAttribute; // Получаем значения промежутка у текущего свойства SerializedProperty minValue = property.FindPropertyRelative("RangeStart"); SerializedProperty maxValue = property.FindPropertyRelative("RangeEnd"); // Переводим во float float newMin = minValue.floatValue; float newMax = maxValue.floatValue; // Запоминаем 40% от ширины пространства для отрисовки float xDivision = position.width * .4f; // Запоминаем 5% от ширины пространства для отрисовки (но посчитано относительно xDivision) float xLabelDiv = xDivision * 0.125f; // Запоминаем 50% от высоты пространства для отрисовки float yDivision = position.height * 0.5f; // Рисуем надпись в пространстве от начала до 40% по ширине и 50% по высоте EditorGUI.LabelField(new Rect(position.x, position.y, xDivision, yDivision), label); // Определяем пространство, оставшееся справа от надписи Rect mmRect = new Rect(position.x + xDivision + xLabelDiv, position.y, position.width - (xDivision + xLabelDiv * 2), yDivision); // ReSharper disable once PossibleNullReferenceException // Рисуем слайдер с двумя концами EditorGUI.MinMaxSlider(mmRect, ref newMin, ref newMax, range.MinLimit, range.MaxLimit); // Определяем пространство слева от слайдера с шириной 5% Rect minRangeRect = new Rect(position.x + xDivision, position.y, xLabelDiv, yDivision); // Какие-то вычисления для более точного позиционирования minRangeRect.x += xLabelDiv * 0.5f - 12; minRangeRect.width = 24; // Рисование текста слева от слайдера EditorGUI.LabelField(minRangeRect, range.MinLimit.ToString()); // Аналогично с правым краем Rect maxRangeRect = new Rect(minRangeRect); maxRangeRect.x = mmRect.xMax + xLabelDiv * 0.5f - 12; maxRangeRect.width = 24; EditorGUI.LabelField(maxRangeRect, range.MaxLimit.ToString()); // Копируем границы пространства, оставшегося справа от надписи (под слайдер) Rect minLabelRect = new Rect(mmRect); // Тут корявые калькуляции, закомментил //minLabelRect.x ;//+= minLabelRect.width * (newMin / range.MaxLimit); //minLabelRect.x -= 12; // Тут не будем ничего сдвигать minLabelRect.y += yDivision; // Мои вычисления вместо старых minLabelRect.width = minLabelRect.width / 2 - 12; newMin = Mathf.Clamp(EditorGUI.FloatField(minLabelRect, newMin), range.MinLimit, newMax); //EditorGUI.LabelField(minLabelRect, newMin.ToString()); Rect maxLabelRect = new Rect(mmRect); maxLabelRect.x += minLabelRect.width + 24; //maxLabelRect.x -= 12; //maxLabelRect.x = Mathf.Max(maxLabelRect.x, minLabelRect.xMax); maxLabelRect.y += yDivision; maxLabelRect.width = maxLabelRect.width / 2 - 12; newMax = Mathf.Clamp(EditorGUI.FloatField(maxLabelRect, newMax), newMin, range.MaxLimit); //EditorGUI.LabelField(maxLabelRect, newMax.ToString()); //Записываем во FloatRange новые данные minValue.floatValue = newMin; maxValue.floatValue = newMax; } }
public override void OnGUI(GUIContent label) { FloatRangeAttribute rangeAttribute = Attribute as FloatRangeAttribute; Value = EditorGUILayout.Slider(label, (float)Value, rangeAttribute.minLimit, rangeAttribute.maxLimit); }
/// <summary> /// Displays the UI to edit the <c>float</c> value. /// </summary> /// <param name="value">The current value.</param> /// <param name="range">The range of valid values the user can select.</param> /// <param name="editorService">The editor service used to display the dropdown control.</param> /// <returns>The value set by the user.</returns> protected abstract float EditValue(float value, FloatRangeAttribute range, IWindowsFormsEditorService editorService);