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
0
Question by boudinov · Jan 15, 2014 at 12:06 PM · guiscale

Incorrect mouse-over behavior using GUI.Window, after scaling UI by changing GUI.matrix

Hello,

When a user switches to a screen resolution, lower than a predefined value, we scale down the whole UI using GUI.Matrix. Everything shows up fine, but when GUI.Window is used, gui elements with Hover style detect mouse incorrectly. Also Rect.Contains(...) starts working incorrectly.

Setting the matrix:

 Vector3 scale = Vector3.zero;
 scale.z = 1;
 scale.y = Screen.height < 1024 ? Screen.height/1024 : 1;
 scale.x = scale.y;
 GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);

This started happening after upgrading from Unity 4.1.0 to 4.2.0. I noticed there is a new GUI.ModalWindow from 4.1.2, which when used, does not produce the above problems as GUI.Window. However using GUI.ModalWindow is not always possible.

This seems like a big problem, especially for Unity games run on game portals, where the resolution is really low by default.

Anyone bumbed into this? Thanks in advance

Comment
Add comment · Show 2
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 Graham-Dunnett ♦♦ · Jan 15, 2014 at 12:49 PM 0
Share

The behaviour you describe is the one I am used to. I've no experience of this working in 4.1.0. You're changing a matrix used to render the GUI, so it's expected that the mouse events cease being aligned. If it was my code I'd just apply the scale in the calls into the GUI functions, so your rects etc get computed using the scale factor.

avatar image Baalhug · Feb 03, 2014 at 03:35 AM 0
Share

I just dont understand what you mean grahamdunnett.

I have the same problem, as many users. I still dont know which version of unity has the solution for this, but i'm not wishing to update because last time i did i had a problem with versions everytime i compiled (i'm using unity free).

Anyway, what i'm doing is scaling the matrix before any GUI element is drawn, so every rect is changed to fit the new screen resolution, the call to GUI.matrix is done in the first line of OnGUI function. So your last sentence does not make sense to me, because GUI rects are already computed with the scale factor. I mean, it works great. However when you pass your mouse over the buttons you notice the area where the button state changes to "On Hover" is displaced.

Am i getting you wrong?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by boudinov · Feb 03, 2014 at 01:15 PM

The problem is the inconsistent behaviour of different API functions. For example, as Grahan mentioned, you can apply the scale in calls to Rect.Contains functions, alright. On the other hand, GUI.Button works fine without modifying anything - clicks on the button are captured correctly. However, using GUIStyle with normal/hover texture backgrounds, does not work correctly, and you have none control over this.

And it seems that in version 4.3, this is all fixed and everything works as expected. Have to double check that though.

Comment
Add comment · 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

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I build a GUI that works on different sized screens? 3 Answers

Is there a way to set a GUI.matrix that will be used by all OnGui() functions? 1 Answer

GUI adapting to screen resolution? 3 Answers

How to scale a GUI (Lagacy) grid? 1 Answer

C# How to Drag and Scale with Mouse Window 0 Answers


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