- Home /
The question is answered, right answer was accepted
Dynamic content in custom EditorWindow
Hi,
I am beginner to the EditorWindow scripting and am in need of support from you guys.
I would like to create a custom EditorWindow with my own dynamic content (just like a list).
I thought it would be simple to make but the following code is not working. Can you help please ?
public void OnGUI() {
if (GUILayout.Button("Press me !")) {
GUILayout.Label("Hello !!!");
Debug.Log("Call from OnGUI");
}
}
I get the message in the Debug.Log() but the label does not show.
I've added the Repaint() to the Update() method and still nothing. When I make the code static i.e. take out the label from the if() the it shows properly ... but this is not what I want to achieve.
Any guides would be helpfull.
Thanks
Answer by FortisVenaliter · Aug 31, 2017 at 09:07 PM
This is because Button() only returns true on the frame it's pressed. So, your label would only draw for 1/60th of a second.
You need to store a separate boolean and have the button toggle it, then check that boolean for whether or not to draw the label.
Works ! Thanks !
public void OnGUI() {
if (GUILayout.Button("Press me !")) pressed = true;
if (pressed) {
GUILayout.Label("Hello !!!");
Debug.Log("Call from OnGUI");
}
}
Follow this Question
Related Questions
Better Unity Event UI 0 Answers
Is there a way to get all editable fields of a component in a script? 2 Answers
Default toggle style 1 Answer
Thumbnails from assets in an EditorWindow 0 Answers
How to get Event.KeyboardEvent from non-focused EditorWindow? 0 Answers