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.