Created
October 20, 2017 05:21
-
-
Save fuzzblob/35bd37a986b6677563be1b367c88ffa8 to your computer and use it in GitHub Desktop.
simple Unity inpector GUI element for a value and a random offset in a single range slider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using UnityEngine; | |
using UnityEditor; | |
public class EditorHelper | |
{ | |
public static GUILayoutOption[] __buttonOptions = new GUILayoutOption[] { GUILayout.Width(120f), GUILayout.ExpandWidth(false) }; | |
public static void RandomRangeSlider(string propertyName, ref float val, ref float rand, ref bool randomEnabled, float min, float max, float resetValue) | |
{ | |
EditorGUILayout.BeginHorizontal(); | |
#region VALUE | |
if (GUILayout.Button(propertyName + val.ToString("0.00"), __buttonOptions)) | |
{ | |
val = resetValue; | |
} | |
val = EditorGUILayout.Slider(val, min, max, GUILayout.ExpandWidth(false)); | |
#endregion | |
GUILayout.Space(30f); | |
#region RANDOM OFFSET | |
if (randomEnabled == false) | |
GUI.enabled = false; | |
if (GUILayout.Button("Rand." + rand.ToString("0.00"), __buttonOptions)) | |
{ | |
rand = resetValue; | |
} | |
rand = EditorGUILayout.Slider(rand, -80f, 0f, GUILayout.ExpandWidth(false)); | |
GUI.enabled = true; | |
#endregion | |
EditorGUILayout.EndHorizontal(); | |
GUILayout.Space(5f); | |
EditorGUILayout.BeginHorizontal(); | |
#region RANGE SLIDER | |
// Random Toggle | |
randomEnabled = EditorGUILayout.Toggle(randomEnabled, GUILayout.MaxWidth(50f)); | |
// make the random setting relative to the main value | |
rand += val; | |
EditorGUILayout.MinMaxSlider(ref rand, ref val, min, max); | |
rand -= val; | |
#endregion | |
EditorGUILayout.EndHorizontal(); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can been seen in action here: https://twitter.com/chtammik/status/921225953312780288