Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Jean-Fabre · Feb 03, 2011 at 06:27 AM · guicoordinatesguiutilitygetlastrect

GUI GetLastRect in absolute coordinates?

Hi,

It's been asked before but title was not very precise, so maybe this will be better.

Basically, GUILayoutUtility.GetLastRect() return the rect in the current Area local coordinates, that is if you begin an area, draw a button and query for the last rect, you'll get x and y = 0. This is fine if you plan on drawing within that area, but this is very problematic if you want to compose something on top of everything, think tooltip. Hence the "need" to have an absolute rect definition of a gui so that at a later time in the OnGUI function, I can come back and add more stuff around a specific area ( mouseposition is not an option on that particula case unfortunatly)

Since the function should be self contained, it's difficult, impractical to query for the last rect on each parent area to compute back the absolute position.

Stuck...

Welcome any hack or proposal :)

Hopefully there is away,

Bye,

Jean

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mike 3 · Feb 03, 2011 at 08:38 AM

In 2.* there was a fairly easy way to do it using GUIClip, but in 3.0 the class got made internal.

A novel way I just thought up could work, but it's just a theory:

//yourRect should be a Rect grabbed from GetLastRect()

Vector2 mousePos = Input.mousePosition; mousePos.y = Screen.height - mousePos.y; Vector2 clippedMousePos = Event.current.mousePosition; yourRect.x += mousePos.x - clippedMousePos.x; yourRect.y += mousePos.y - clippedMousePos.y;

//yourRect should now be in absoloute coordinates.

A little bizarre, but it made me laugh when it popped into my head

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jean-Fabre · Feb 03, 2011 at 01:27 PM 0
Share

Nice :) thank you for your expertise and time, Your help is very much appreciated and makes my journey into Unity a great experience :)

avatar image trentdk · Sep 29, 2011 at 08:11 PM 0
Share

What kind of voodoo is this?! Too bad the coordinates change slightly as the mouse moves around.

avatar image stevethorne · Nov 06, 2014 at 03:47 PM 0
Share

It seems as though Input.mousePosition is always 0,0 in Editor because Input.mousePosition isn't calculated during editor gui. Does anyone know how I can do this in an EditorWindow?

avatar image
2

Answer by yoyo · Feb 03, 2011 at 05:10 PM

GUIToScreenPoint

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mike 3 · Feb 04, 2011 at 04:45 AM 0
Share

I can't believe I'd forgotten that one, +1

avatar image trentdk · Oct 29, 2011 at 03:31 PM 0
Share

This can't be the answer to the OP's question. GUIToScreenPoint just takes a Vector2 and converts it based on the idea that the "sceen" origin is different than the "gui" origin.

Screen origin = bottom left

GUI origin = top left

So on 1024x768, GUI (0,0) becomes (768,0)... that has nothing to do with the OP's question.

I too would like a GUILayoutUtility.GetLastRectAbsolute().

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

how to find out the absolute coordinate? 0 Answers

Help in GUI issue - Can't lose focus of a dropdown list when mouse clicks somewhere else? 0 Answers

how do I make a gui element appear in front of an object 1 Answer

Generating a particle effect on top of a GUIElement 1 Answer

Fix a GUI's position relative to a 3D object 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges