- Home /
EditorWindow: Use toggle to disable/enable other controls?
Hey guys,
I'm kind of new to editor scripting. So here's what I have:
What I want is:
When "Time effect" is ticked, all the controls below gets enabled. (That is easily achieved by
EditorGUILayout.BeginToggleGroup
)If neither "Permanent" nor "Overtime" is ticked, nothing gets disabled (like you see in the picture)
If "Permanent" is ticked, then "Overtime" and "Duration" are disabled (not hidden or blown away)
If "Overtime" is ticked, then "Permanent" and "Tick" are disabled.
Again, I wanna disable them, not hide them. Any idea how? The code I have now, hides them:
using UnityEditor;
using UnityEngine;
public class MyWindow : EditorWindow
{
string myString = "Hello World";
bool group_timeEffect;
bool isPermanent;
bool isDividedOvertime;
float duration;
float tick;
// Add menu item named "My Window" to the Window menu
[MenuItem("Window/My Window")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(MyWindow));
}
void OnGUI()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField("Text Field", myString);
group_timeEffect = EditorGUILayout.BeginToggleGroup("Time effect", group_timeEffect);
if (!isDividedOvertime) {
isPermanent = EditorGUILayout.Toggle("Permanent", isPermanent);
tick = EditorGUILayout.FloatField("Tick", tick);
}
if (!isPermanent) {
isDividedOvertime = EditorGUILayout.Toggle("Overtime", isDividedOvertime);
duration = EditorGUILayout.FloatField("Duration", duration);
}
EditorGUILayout.EndToggleGroup();
}
}
I'm using EditorWindow
just to see how it goes. Originally I plan to use this code, to make a custom inspector for a ScriptableObject
of mine (So... I'm hoping for a solution that works there as well), which at the moment looks very ugly:
Any help would be appreciated. Thanks.
Sorry I didn't get what you mean or aim by that code snippet. Are you asking what do I mean by hiding or disabling?
Answer by Jamora · Dec 21, 2013 at 08:03 PM
Your OnGUI should look like
void OnGUI()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField("Text Field", myString);
group_timeEffect = EditorGUILayout.BeginToggleGroup("Time effect", group_timeEffect);
EditorGUI.BeginDisabledGroup(isDividedOvertime); //<---
isPermanent = EditorGUILayout.Toggle("Permanent", isPermanent);
tick = EditorGUILayout.FloatField("Tick", tick);
EditorGUI.EndDisabledGroup(); //<---
EditorGUI.BeginDisabledGroup(isPermanent); //<---
isDividedOvertime = EditorGUILayout.Toggle("Overtime", isDividedOvertime);
duration = EditorGUILayout.FloatField("Duration", duration);
EditorGUI.EndDisabledGroup(); //<---
EditorGUILayout.EndToggleGroup();
}
Your answer
Follow this Question
Related Questions
Positioning a button at the bottom of an editor window 1 Answer
Is it possible to store and display EditorGUILayout.Toggles? 0 Answers
How to combine two buttons in one. Editor window 2 Answers
In EditorGUI, how to implement a large Editable Panel like what you can do in an UML diagram? 0 Answers
Small GUILayout button 1 Answer