Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Aspect ratio change in editor Game window callback?

Discussion in 'Scripting' started by Nims, Jul 27, 2014.

  1. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
    I am looking for a way to get information on if the editor "Game" window/panel has had it's resolution/Aspect ration changed during edit time.
    Is there a callback for this? If not is there any other hack I can tap into to check this?
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    I think you just have to poll to see if Screen.width or Screen.height change. It's not ideal, but thankfully it's not something you'd usually have to worry about outside of the Editor, so you can probably safely make it Editor-only code.
     
  3. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
    Well this is what I got so far:
    Using the directive [ExecuteInEditMode] actually does receive a notification on resolution changes changes when drawing the "Game" window, this is done best it seems through the OnRenderObject() method.
    The problem is it doesn't receive this notification if you change the resolution through the left top drop down in the "Game" window. You need to actually press in the game window again trigger the OnRenderObject() method.

    From the Unity documentation: http://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html
    "The functions are not called constantly like they are in play mode.
    - Update is only called when something in the scene changed.
    - OnGUI is called when the Game View recieves an Event.
    - OnRenderObject and the other rendering callback functions are called on every repaint of the Scene View or Game View."

    Any suggestion on how to solve this last case or how to implement your suggested polling?
     
  4. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    The EditorApplication.update event might be a good place to implement polling in the editor.
     
  5. Untherow

    Untherow

    Joined:
    Jun 19, 2016
    Posts:
    8
    I noticed MonoBehaviour.Update() triggers on Game window resolution change when using directive [ExecuteInEditMode].

    Works just fine for me!