Search Unity

Screen View and Game View GUI don't match

Discussion in 'Immediate Mode GUI (IMGUI)' started by DrDecipher, Oct 9, 2014.

  1. DrDecipher

    DrDecipher

    Joined:
    Dec 5, 2012
    Posts:
    54
    I'm projecting vertices and vertex numbers to the camera view for debugging.

    I've been having some difficulty figuring out what is causing the offset of drawing to the screen in the Scene View. At first I thought this was an issue with WorldToScreen, but it is actual how things are being drawn as a whole.


    In the game GUI this draws a 1 pixel red line around all edges of the screen correctly.
    Code (CSharp):
    1.  void OnGUI()
    2.     {
    3.         if (screenDrawGUID)
    4.         {
    5.             screenDrawTex = new Texture2D(Screen.width, Screen.height);
    6.             for (int i = 0; i < Screen.width; i++)
    7.             {
    8.                 for (int j = 0; j < Screen.height; j++)
    9.                 {
    10.                     if (i < 1 | i > Screen.width - 2 | j < 1 | j > Screen.height - 2)
    11.                         screenDrawTex.SetPixel(i, j, Color.red);
    12.                     else
    13.                         screenDrawTex.SetPixel(i, j, new Color(0,0,0,0) );
    14.                 }
    15.             }
    16.             screenDrawTex.Apply();
    17.             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), screenDrawTex, ScaleMode.ScaleToFit);
    18.         }
    19.     }
    However in the Scene View you have to offset everything seemingly arbitrarily...
    This code is what it taked for the Docked Scene View:
    Code (CSharp):
    1. // SceneView Docked
    2.         if (screenDrawSVD)
    3.         {
    4.             screenDrawTex = new Texture2D(Screen.width, Screen.height);
    5.             for (int i = 0; i < Screen.width; i++ )
    6.             {
    7.                 for (int j = 0; j < Screen.height; j++)
    8.                 {
    9.                     if (i < 1 | i > Screen.width - 6 | j < 39 | j > Screen.height - 2)
    10.                         screenDrawTex.SetPixel(i, j, Color.red);
    11.                 }
    12.             }
    13.             screenDrawTex.Apply();
    14.             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), screenDrawTex, ScaleMode.ScaleToFit);
    15.         }
    And even stranger when the Scene View is floating the numbers change again to accomplish the same one pixel line around the edges.
    Code (CSharp):
    1.         // SceneView Float
    2.         if (screenDrawSVF)
    3.         {
    4.             screenDrawTex = new Texture2D(Screen.width, Screen.height);
    5.             for (int i = 0; i < Screen.width; i++)
    6.             {
    7.                 for (int j = 0; j < Screen.height; j++)
    8.                 {
    9.                     if (i < 1 | i > Screen.width - 2 | j < 40 | j > Screen.height - 2)
    10.                         screenDrawTex.SetPixel(i, j, Color.red);
    11.                 }
    12.             }
    13.             screenDrawTex.Apply();
    14.             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), screenDrawTex, ScaleMode.ScaleToFit);
    15.         }
    Anyone have thoughts about what is causing the offset in the Scene View? The offset is annoying at best.

    Thanks,
    Doc