EditorWindow: Use toggle to disable/enable other controls?

Hey guys,

I’m kind of new to editor scripting. So here’s what I have:

19608-effectcausernew.png

What I want is:

  1. When “Time effect” is ticked, all the controls below gets enabled. (That is easily achieved by EditorGUILayout.BeginToggleGroup)
  2. If neither “Permanent” nor “Overtime” is ticked, nothing gets disabled (like you see in the picture)
  3. If “Permanent” is ticked, then “Overtime” and “Duration” are disabled (not hidden or blown away)
  4. 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:

19609-so.png

Any help would be appreciated. Thanks.

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();
	}