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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to determinate playerwindow resolution in script?

Discussion in '2D' started by mshunko, Aug 29, 2015.

  1. mshunko

    mshunko

    Joined:
    Jul 16, 2015
    Posts:
    4
    Hi,
    Unity v5.1.3, platform Android.
    How to determinate playerwindow resolution in script? that i set in editor window like WXGA,WVGA.
    Screen.currentResolution return default resolution or resolution of my desktop screen.
    Camera.main.pixelRect return resolution of playereditorwindow.
    Thanks.
     
  2. mshunko

    mshunko

    Joined:
    Jul 16, 2015
    Posts:
    4
    Code (CSharp):
    1.     void SetScreenWidthAndHeightFromEditorGameViewViaReflection()
    2.     {
    3.         var gameView = GetMainGameView();
    4.         var prop = gameView.GetType().GetProperty("currentGameViewSize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
    5.         var gvsize = prop.GetValue(gameView, new object[0]{});
    6.         var gvSizeType = gvsize.GetType();
    7.        
    8.         debug_h = (int)gvSizeType.GetProperty("height", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0]{});
    9.         debug_w = (int)gvSizeType.GetProperty("width", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0]{});
    10.     }
    11.    
    12.     UnityEditor.EditorWindow GetMainGameView()
    13.     {
    14.         System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
    15.         System.Reflection.MethodInfo GetMainGameView = T.GetMethod("GetMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
    16.         System.Object Res = GetMainGameView.Invoke(null,null);
    17.         return (UnityEditor.EditorWindow)Res;
    18.     }