using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
public class Sorting : EditorWindow
{
string objectsName;
bool groupEnabled;
bool myBool = true;
float myFloat = 1.23f;
// Add menu named "Objects" to the GameObject menu
[MenuItem("GameObject/Objects")]
static void Init()
{
// Get existing open window or if none, make a new one:
Sorting window = (Sorting)EditorWindow.GetWindow(typeof(Sorting));
window.Show();
}
void OnGUI()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
objectsName = EditorGUILayout.TextField("By Name", objectsName);
groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle("Toggle", myBool);
myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup();
GUILayout.FlexibleSpace();
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
EditorGUI.BeginDisabledGroup(objectsName == "");
if (GUILayout.Button("Name"))
{
}
EditorGUILayout.EndHorizontal();
EditorGUI.EndDisabledGroup();
}
}
This is a EditorWindow type script.
And i want to make that when i display this window in the editor by default the button will be disabled.
Then if i type anything inside the EditorGUILayout.TextField the button will be enabled(true).
Then if i delete the text from the EditorGUILayout.TextField the button will be disabled(enabled false) again.
The problem is i can’t make the button start by default disabled.
I’m trying to use BeginDisabledGroup and EditorGUIEndDisabledGroup but this make the button start by defaulr enbaled true and not disabled. Only if i will type something and delete it the button will be disabled but i want the button to start by default disabled. Then when i type something it will be enabled(enable true).
I tried before:
GUI.enabled = (objectsName != "");
But it didn’t give me what i need.