Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Gizmos.DrawGUITexture rounding input rect

Discussion in 'Immediate Mode GUI (IMGUI)' started by AndyUr, May 30, 2016.

  1. AndyUr

    AndyUr

    Joined:
    Aug 17, 2015
    Posts:
    19
    When I try using:

    Code (csharp):
    1.     void OnDrawGizmos()
    2.     {
    3.         Gizmos.DrawGUITexture(new Rect(0.25f, 0, 1, 1), texture);
    4.     }
    The floating point values in the Rect get rounded to the nearest integer. In this case, Rect(0,0,1,1). Is this a bug, or a very unfortunate intended behaviour?
     
  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,229
    DrawGUITexture uses screen coordinates which are integers. If you wish to position say 25% from the left you can calculate this with Screen.Width / 4f.

    So you would place the screen coordinates (as Int) in the Rect().

    http://docs.unity3d.com/ScriptReference/Gizmos.DrawGUITexture.html
     
  3. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    114
    I have the same problem but I can't see why... I'm trying to render prefabs contents (Textures from Sprite Renderers) in the editor scene without instantiating them (preview a prefab in the scene as a Gizmo). While it's moslty ok, I'm having bad times with their position. Any help would be greatly appreciated. Here is the code : https://pastebin.com/0PZ6sewE

    While the rect.center is properly set, DrawGUITexture just snap the texture somewhere else.