public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { int originalIndentLevel = EditorGUI.indentLevel; EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); EditorGUI.indentLevel = 0; SerializedProperty min = property.FindPropertyRelative("min"); SerializedProperty max = property.FindPropertyRelative("max"); float minValue = min.floatValue; float maxValue = max.floatValue; position.width /= 3; minValue = EditorGUI.FloatField(position, minValue); position.x += position.width; FloatRangeSliderAttribute limit = attribute as FloatRangeSliderAttribute; EditorGUI.MinMaxSlider(position, ref minValue, ref maxValue, limit.Min, limit.Max); position.x += position.width; maxValue = EditorGUI.FloatField(position, maxValue); min.floatValue = minValue; max.floatValue = maxValue; EditorGUI.EndProperty(); EditorGUI.indentLevel = originalIndentLevel; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { int originalIndentLevel = EditorGUI.indentLevel; EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel( position, GUIUtility.GetControlID(FocusType.Passive), label ); EditorGUI.indentLevel = 0; SerializedProperty minProperty = property.FindPropertyRelative("min"); SerializedProperty maxProperty = property.FindPropertyRelative("max"); float minValue = minProperty.floatValue; float maxValue = maxProperty.floatValue; float fieldWidth = position.width / 4; float sliderWidth = position.width / 2; position.width = fieldWidth; minValue = EditorGUI.FloatField(position, minValue); position.x += fieldWidth + 4f; position.width = sliderWidth; FloatRangeSliderAttribute limit = attribute as FloatRangeSliderAttribute; EditorGUI.MinMaxSlider(position, ref minValue, ref maxValue, limit.Min, limit.Max); position.width = fieldWidth; position.x += sliderWidth + 4f; maxValue = EditorGUI.FloatField(position, maxValue); if (minValue < limit.Min) { minValue = limit.Min; } else if (minValue > limit.Max) { minValue = limit.Max; } if (maxValue < minValue) { maxValue = minValue; } else if (maxValue > limit.Max) { maxValue = limit.Max; } minProperty.floatValue = minValue; maxProperty.floatValue = maxValue; EditorGUI.EndProperty(); EditorGUI.indentLevel = originalIndentLevel; }
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { int originIndentLevel = EditorGUI.indentLevel; EditorGUI.BeginProperty(rect, label, property); rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label); EditorGUI.indentLevel = 0; SerializedProperty minProperty = property.FindPropertyRelative("min"); SerializedProperty maxProperty = property.FindPropertyRelative("max"); float minValue = minProperty.floatValue; float maxValue = maxProperty.floatValue; // Draw “Min” float field float fieldWidth = rect.width / 4f - 4f; float sliderWidth = rect.width / 2f; rect.width = fieldWidth; minValue = EditorGUI.FloatField(rect, minValue); rect.x += fieldWidth + 4f; rect.width = sliderWidth; // Minmax Slider FloatRangeSliderAttribute limit = attribute as FloatRangeSliderAttribute; EditorGUI.MinMaxSlider(rect, ref minValue, ref maxValue, limit.Min, limit.Max); // Draw "Max" float field rect.x += sliderWidth + 4f; rect.width = fieldWidth; maxValue = EditorGUI.FloatField(rect, maxValue); if (minValue < limit.Min) { minValue = limit.Min; } else if (minValue > limit.Max) { minValue = limit.Max; } if (maxValue < minValue) { maxValue = minValue; } else if (maxValue > limit.Max) { maxValue = limit.Max; } minProperty.floatValue = minValue; maxProperty.floatValue = maxValue; EditorGUI.EndProperty(); EditorGUI.indentLevel = originIndentLevel; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); int indent = EditorGUI.indentLevel; position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); EditorGUI.indentLevel = 0; SerializedProperty minProperty = property.FindPropertyRelative("min"); SerializedProperty maxProperty = property.FindPropertyRelative("max"); float minValue = minProperty.floatValue; float maxValue = maxProperty.floatValue; float fieldWidth = position.width / 5f - 4f; float sliderWidth = position.width / 1.7f; position.width = fieldWidth; minValue = EditorGUI.FloatField(position, minValue); position.x += fieldWidth + 4f; position.width = sliderWidth; FloatRangeSliderAttribute limit = attribute as FloatRangeSliderAttribute; EditorGUI.MinMaxSlider(position, ref minValue, ref maxValue, limit.Min, limit.Max); position.x += sliderWidth + 4f; position.width = fieldWidth; maxValue = EditorGUI.FloatField(position, maxValue); minValue = Mathf.Min(minValue, maxValue); minValue = Mathf.Max(minValue, limit.Min); maxValue = Mathf.Max(minValue, maxValue); maxValue = Mathf.Min(maxValue, limit.Max); minProperty.floatValue = minValue; maxProperty.floatValue = maxValue; EditorGUI.EndProperty(); EditorGUI.indentLevel = indent; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //使用FloatRangeDrawer的GUI //base.OnGUI(position,property,label); int originalIndentLevel = EditorGUI.indentLevel; EditorGUI.BeginProperty(position, label, property); //获取变量名 position = EditorGUI.PrefixLabel( position, GUIUtility.GetControlID(FocusType.Passive), label ); EditorGUI.indentLevel = 0; //获取property的min和max SerializedProperty minProperty = property.FindPropertyRelative("min"); SerializedProperty maxProperty = property.FindPropertyRelative("max"); //获取值 float minValue = minProperty.floatValue; float maxValue = maxProperty.floatValue; float fieldWidth = position.width / 4f - 4f; float sliderWidth = position.width / 2f; position.width = fieldWidth; minValue = EditorGUI.FloatField(position, minValue); position.x += fieldWidth + 4f; position.width = sliderWidth; FloatRangeSliderAttribute limit = attribute as FloatRangeSliderAttribute; //画Slider EditorGUI.MinMaxSlider( position, ref minValue, ref maxValue, limit.Min, limit.Max ); position.x += sliderWidth + 4f; position.width = fieldWidth; maxValue = EditorGUI.FloatField(position, maxValue); if (minValue < limit.Min) { minValue = limit.Min; } if (maxValue < minValue) { maxValue = minValue; } else if (maxValue > limit.Max) { maxValue = limit.Max; } minProperty.floatValue = minValue; maxProperty.floatValue = maxValue; EditorGUI.EndProperty(); EditorGUI.indentLevel = originalIndentLevel; // int originalIndentLevel = EditorGUI.indentLevel; // EditorGUI.BeginProperty(position, label, property); // //位置调整 // position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); // EditorGUI.indentLevel = 0; // //返回一个 // SerializedProperty minProperty = property.FindPropertyRelative("min"); // SerializedProperty maxProperty = property.FindPropertyRelative("max"); // float minValue = minProperty.floatValue; // float maxValue = maxProperty.floatValue; // float fieldWidth = position.width / 4f - 4f; // float sliderWidth = position.width / 2f; // position.width = fieldWidth; // minValue = EditorGUI.FloatField(position, minValue); // position.x += fieldWidth + 4; // position.width = sliderWidth; // FloatRangeSliderAttribute limit = attribute as FloatRangeSliderAttribute; // minProperty.floatValue = minValue; // maxProperty.floatValue = maxValue; // EditorGUI.MinMaxSlider( // position, ref minValue, ref maxValue, limit.Min, limit.Max // ); // position.x += sliderWidth + 4f; // position.width = fieldWidth; // maxValue = EditorGUI.FloatField(position, maxValue); // if (minValue < limit.Min) // { // minValue = limit.Min; // } // if (maxValue < minValue) // { // maxValue = minValue; // } // else if (maxValue > limit.Max) // { // maxValue = limit.Max; // } // EditorGUI.EndProperty(); // EditorGUI.indentLevel = originalIndentLevel; }