Search Unity

Any way to detect when an EditorWindow is being resized?

Discussion in 'Immediate Mode GUI (IMGUI)' started by JoePatrick, Apr 27, 2019.

  1. JoePatrick

    JoePatrick

    Joined:
    Nov 3, 2013
    Posts:
    121
    So I have a function that needs to be called everytime my EditorWindow is manually resized however it is quite a slow function so I don't want to call it constantly while resizing the window, just once when the resizing has finished. Is there anyway to detect when a Window is being resized other than just checking the size against the last frame? Because that method isn't very effective as when dragging slowly for example, the size doesn't actually change every frame so you can't clearly detect when the resizing starts/stops

    Thanks :)

    edit
    So I have this, and it works except for that I have to click the EditorWindow after resizing for it to trigger. My guess being that the resizing of the window "uses" the MouseUp event so it can't be detected. Any suggestions?
    Code (CSharp):
    1. if (window.position.size != lastWindowSize)
    2.      resizeChk = true;
    3. else if(Event.current.isMouse && Event.current.type == EventType.MouseUp)
    4.      resizeChk = false;
    5.          
    6. lastWindowSize = window.position.size;
     
    Last edited: Apr 27, 2019
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    What you have looks good. What I think you want to do is conceptualize two states... "is moving" and "was moving". So, first establish your window size has changed during some frame, then the next frame that it doesn't change size you can guess that the resizing is done, call your function, and reset your counters.

    It's not perfect but if you can't reliably get the MouseEvent stuff this might be as close as you can get?