how can I disable 2 bools when one is clicked? there are a total of 3 and only one can be active at any time, and one has to be enabled at all times. how can I do this with an editor window? disableding them with an if statement did not work
using UnityEngine;
using UnityEditor;
public class BoolSelect : EditorWindow
{
bool bool1 = false;
bool bool2 = false;
bool bool3 = false;
[MenuItem("Examples/BoolSelect")]
static void Init()
{
BoolSelect window = (BoolSelect)EditorWindow.GetWindow(typeof(BoolSelect), true, "BoolSelect Window");
window.Show();
}
void OnGUI()
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Select 1"))
{
bool1 = true;
bool2 = false;
bool3 = false;
}
EditorGUILayout.Toggle("bool1", bool1);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Select 2"))
{
bool1 = false;
bool2 = true;
bool3 = false;
}
EditorGUILayout.Toggle("bool2", bool2);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Select 3"))
{
bool1 = false;
bool2 = false;
bool3 = true;
}
EditorGUILayout.Toggle("bool3", bool3);
EditorGUILayout.EndHorizontal();
}
}
That’ll show toggles that are interactable, but doesn’t do anything.
This just shows the toggles:
private bool ToggleChangedToTrue(string label, bool currentValue) {
var result = EditorGUILayout.Toggle(label, currentValue);
return result && !currentValue;
}
public override void OnInspectorGUI() {
var bool1ChangedToTrue = ToggleChangedToTrue("Bool 1", bool1);
var bool2ChangedToTrue = ToggleChangedToTrue("Bool 2", bool2);
var bool3ChangedToTrue = ToggleChangedToTrue("Bool 3", bool3);
if (bool1ChangedToTrue || bool2ChangedToTrue || bool3ChangedToTrue) {
bool1 = bool1ChangedToTrue;
bool2 = bool2ChangedToTrue;
bool3 = bool3ChangedToTrue;
}
}
You can also use a SelectionGrid, which is even easier, but maybe doesn’t look as good:
public override void OnInspectorGUI() {
EditorGUI.BeginChangeCheck();
selected = GUILayout.SelectionGrid(selected, new[] {"Bool1", "Bool2", "Bool3"}, 1, GUI.skin.toggle);
if (EditorGUI.EndChangeCheck()) {
bool1 = selected == 0;
bool2 = selected == 1;
bool3 = selected == 2;
}
}
Thanks this worked great and is pretty much exactly what I was looking for.
sorry johne your way would have worked but wasn’t quite the functionality I wanted.