- Home /
How can i make a text changed event in EditorGUILayout.TextField ?
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();
GUI.enabled = false;
if (GUI.changed)
{
GUI.enabled = true;
}
if (GUILayout.Button("Name"))
{
}
EditorGUILayout.EndHorizontal();
}
I want to make that if i type something inside the EditorGUILayout.TextField it will enable the button and if it's empty then disable again the button.
I tried this part:
GUI.enabled = false;
if (GUI.changed)
{
GUI.enabled = true;
}
It's changing it to false the button but never change it back to true. I want when i type anything in the EditorGUILayout.TextField it will enable true the button the "Name" and if i will delete the text from the EditorGUILayout.TextField it will enable false the button again.
Answer by tomekkie2 · Dec 06, 2016 at 12:54 PM
Try this:
string objectsName = "";
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 working but when i display the window the button is starting as enabled true. Then when i type something and delete it the button is enabled false. How can i make that the button will start by default as enabled false ? And then when i will type something it will be enabled true and when delete enabled false again.
Try again with
EditorGUI.BeginDisabledGroup
I have corrected the above code. If that works, I cound convert it to answer.
It's working the other way now. The wrong way.
When i display the window the button is enabled false but then when i type something the button still false then when i delete the text the button enable true then if i type again the button is false.
Ah sorry!!! should be == ins$$anonymous$$d of !=
EditorGUI.BeginDisabledGroup (objectsName == "");
Your answer
Follow this Question
Related Questions
Why when creating new animator controller for the character the character is not walking right ? 0 Answers
How can i Instantiate on the terrain from left to right ? 0 Answers
Why the tile map scripts take almost all the cpu usage ? cpu usage is getting to 99% at times 1 Answer
How can i rotate object by pressing on key R and keep object facing to me my self ? 0 Answers
Why it;s never getting to the OnMouseDown function when clicking with the mouse ? 1 Answer