Notifications
Article
Custom MinMax float with manual modifier
Published a year ago
98
0
GUI element for a MinMax float with manual modifier
/// <summary> /// Simple Min Max for Float with modifier /// </summary> /// <param name="name"> Will be show on top of the slider</param> /// <param name="min">The min value</param> /// <param name="max">The max value</param> /// <param name="minValue">The min value for the float</param> /// <param name="maxValue">THe max value for the float</param> void MinMaxFloat(string name, ref float min, ref float max, float minValue, float maxValue) { EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); min = EditorGUILayout.FloatField(min, GUILayout.Width(50)); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField(name, EditorStyles.boldLabel, GUILayout.Width(11f * name.Length)); GUILayout.FlexibleSpace(); max = EditorGUILayout.FloatField(max, GUILayout.Width(50)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.MinMaxSlider(ref min, ref max, minValue, maxValue); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
This simple function allow you to display a custom minmax float with manual modifier. Can be use for vector3:
/// <summary> /// Simple Min Max for Vector 3 with float modifier /// </summary> /// <param name="min"> The min Vector3</param> /// <param name="max"> The max Vector3</param> /// <param name="minValue"> The min value for the Vector3</param> /// <param name="maxValue"> The max value for the Vector3</param> void MinMaxVector(ref Vector3 min, ref Vector3 max, Vector3 minValue, Vector3 maxValue) { EditorGUILayout.Space(); MinMaxFloat("X", ref min.x, ref max.x, minValue.x, maxValue.x); MinMaxFloat("Y", ref min.y, ref max.y, minValue.y, maxValue.y); MinMaxFloat("Z", ref min.z, ref max.z, minValue.z, maxValue.z); }
and vector3 with uniform parameter :
/// <summary> /// Simple Min Max for Vector 3 with float modifier /// </summary> /// <param name="min"> The min Vector3</param> /// <param name="max"> The max Vector3</param> /// <param name="minValue"> The min value for the Vector3</param> /// <param name="maxValue"> The max value for the Vector3</param> void MinMaxVectorSize(ref bool uniform, ref Vector3 min, ref Vector3 max, Vector3 minValue, Vector3 maxValue) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Uniform", GUILayout.Width(50)); uniform = EditorGUILayout.Toggle(uniform, GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); if (uniform== false) { MinMaxFloat("X", ref min.x, ref max.x, minValue.x, maxValue.x); MinMaxFloat("Y", ref min.y, ref max.y, minValue.y, maxValue.y); MinMaxFloat("Z", ref min.z, ref max.z, minValue.z, maxValue.z); } else { MinMaxFloat("XYZ", ref min.x, ref max.x, minValue.x, maxValue.x); min = Vector3.one * min.x; max = Vector3.one * max.x; } }
Baptiste
Tool Programmer and Developer - Programmer
7
Comments