Search Unity

GUITexture Vs Rect Positions

Discussion in 'Scripting' started by amcclay, Jun 9, 2009.

  1. amcclay

    amcclay

    Joined:
    Aug 8, 2006
    Posts:
    143
    Hey guys. So, I'm trying to "roll my own" gui for a simple app. Since this app will ultimately make its way to the iPhone I want to avoid using the 'GUI.' stuff since, as I understand it, this method is somewhat of a resource hog on the iPhone.

    What I am trying to do is simply make a set up where I can create a Rect that is accurately placed over my GUITexture at all times (adjusting for different window sizes as well).

    Apparently there is a difference in the way the GUITexture coordinates are figured versus the way the Rect position is figured.

    Are there any solutions to making sure that I can have, say, a 64x64 GUITexture stay within a 64x64 Rect at any window size?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Just use GetScreenRect().

    --Eric
     
  3. amcclay

    amcclay

    Joined:
    Aug 8, 2006
    Posts:
    143
    Unfortunately, just doing this:

    Code (csharp):
    1. Rect guiRectTest = myGuiTexture.GetScreenRect();
    2. GUI.Box (guiRectTest, "Test");
    3.  
    results in a rectangle drawn on the opposite end of the screen from the texture it's supposed to appear over.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OnGUI uses top-down coords; screen rects are normally bottom-up. Realmaze3D uses GetScreenRect with no issues.

    --Eric
     
  5. amcclay

    amcclay

    Joined:
    Aug 8, 2006
    Posts:
    143
    Yep, OnGUI and apparently also mousePosition uses top-down coords. Not sure why screen rects use something different.

    Is there anyway to convert between the two positions to reposition one element or another (in script) so they always match up?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Flip the y element based on screen height (i.e., var flippedY = Screen.height - Input.mousePosition.y). Only OnGUI (and associated events like Event.mousePosition) is top-down; Input.mousePosition etc. are all bottom-up.

    --Eric