Editor Window , Is There no Callback on GUI.Button??

I studied Android for long time.
In Android. u can add callback (like onClick) on view simply.

Button button1 = new Button(context);
button1.setOnClickListener(new OnClickListener(){
public void onClick(int id)
// Contents…


but WindowEditor in Unity,

There is no callback. and just handle events with ‘if’.


if (GUI.Button(new Rect(100,100 , 100, 100), “Sample”))

but this case, It seems to impossible to identify “mouse down” and “mouse up”.
u can just know it is clicked or not. (just quick mouse down and up, If you drag the button or make slow down and up, unity doesn’t see it as a click so ‘Debug.Log is not executed’)

so these are my question.

  1. Is there more elaborate way to handle Event on Button? I want to drag buttons.
  2. I want to manage GUI things more OOP-likely. for example, I want to store rect information on instances. (Just Image dragging some buttons, It will be more easier if I can make Button objects) not like code that I showed you. Is there a way to do.
    3.If you have some nice document for EditorWIndow please let me know.

thank you :slight_smile:

Unity has 2 GUI systems.

  • Immediate GUI - Available in Editor (By ‘Editor’ I mean Custom Editors and Inspectors and stuff like that). Also available at Runtime but its deprecated in favor of uGUI (since Unity 4.6)
  • Retained GUI - Available only at runtime as uGUI (since Unity 4.6)

Coming from ‘Android’ you are probably used to a retained GUI. One that you declare once and then can safely assume the ‘OOP-like’ object for a Button or other control continues to exists until you destroy it. This allows for state during its lifetime which allows for callbacks.

In Immediate GUI, you declare a control like a button and that declaration is RECALLED MANY TIMES per second. Not just once per render, but much more. Some info on it is here. Unity - Manual: IMGUI Basics. Due to how the system works if it was not recalled it would dissapear. It has no lifetime of its own and thus no callbacks.

I enjoy the uGUI system for runtime use. Its great. It would be nice to have that same level of control within the Editor for use in Custom Inspectors, however I’m not sure that is possible nor will ever happen. So for now, good luck with the immediate GUI :slight_smile: