Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Screen.height/width via [ContextMenu] click return dimensions of righ-clicked editor panel

Discussion in '5.5 Beta' started by NoseKills, Nov 28, 2016.

  1. NoseKills

    NoseKills

    Joined:
    Jun 4, 2013
    Posts:
    25
    I got this piece of code attached to an empty GameObject in an otherwise empty scene in 5.5.0f2

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class Test : MonoBehaviour {
    5.  
    6.     void Start() {
    7.         Debug.Log("START width " + Screen.width + " height " + Screen.height);
    8.     }
    9.  
    10.     [ContextMenu("Test")]
    11.     void TestMe() {
    12.         Debug.Log("TEST width " + Screen.width + " height " + Screen.height);
    13.     }
    14. }
    15.  
    When I press Play, and then right-click the Monobehaviour and click on the "Test" item in the dropdown, i get these outputs:

    resolution1.PNG
    When I resize the inspector panel of holding the MonoBehaviour, the output produced through the context-menu click changes to match the size of the inspector panel (I believe). resolution2.PNG
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Sounds like a bug. Have you filed a bug report?
     
  3. NoseKills

    NoseKills

    Joined:
    Jun 4, 2013
    Posts:
    25
  4. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
  5. NoseKills

    NoseKills

    Joined:
    Jun 4, 2013
    Posts:
    25
    Mmkay. Seems like Camera.pixelHeight and pixelWidth are the correct values to use. I think there's even some Unity learning material that should be changed to use these values instead of Screen.width/height. I'm pretty sure that's where i picked up the habit of using Screen.XXXX values years ago.
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Yes it seems to be by design. Screen returns the state of the current rendering context (which is the inspector in this case). Much of the editor and many 3rd-party editor extensions rely on this behavior. However, I agree that the API is a bit vague about what it should be used for. We've been looking into a better solution for this API.