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 Bigproblem01 · Jul 11, 2014 at 04:16 PM · iphonescalesizeipadngui

NGUI resizes fine in engine but not on actual devices

Hi guys, I have a GUI, part of it is NGUI (round buttons and bars in the corners) and part is a rect() (the middle one).

What I want to do is resize the entire guy according to the screen size. So I multiply all the dimensions of NGUI bars and rect bar with Screen.width.

here's my code for them:

  • for rect

       {
    
             width = Screen.width * 0.5f;
          float currentWidth = width * _widthCoef * 0.715f;
         guiTexture.pixelInset = new Rect(-currentWidth * 0.5f, Screen.height * 0.5f - offsetY * Screen.height, currentWidth, height * Screen.height);
    
    

    }

  • for NGUI bars

       {
    
             batteryBG.width = Mathf.FloorToInt(Screen.width * 0.25f);
         scoreBG.width = Mathf.FloorToInt(Screen.width * 0.25f);
    
    

    }

When I test in Unity in game window with different resolutions, it shows fine, here are the pictures:

alt text

But when I actually build the game on an iPad or iPhone the rect remains as it should (this means my code is correct), but the NGUI elements behave strangely. Here's an approximate picture of how it looks when I build it on iPad

alt text

Any ideas of what might be causing this? At first I though that maybe screen.width is not the correct method and I need something like a resolution or pixel size but the rect works as expected so I guess this is a speciality of NGUI to react like this? What am I doing wrong?

Thanks in advance!

problem.png (158.4 kB)
problem2.png (49.6 kB)
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 Sisso · Jul 11, 2014 at 04:21 PM 0
Share

I think that you will receive a better support using ngui forums.

avatar image Bigproblem01 · Jul 11, 2014 at 10:01 PM 0
Share

I'll try posting there too

2 Replies

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

Answer by alwayscodeangry · Jul 12, 2014 at 12:05 AM

You should be able to correct this by multiplying the screen width by the ratio between your fixed NGUI size and the screen size. Try using:

 float width = Screen.width * ((float)uiRoot.activeHeight / Screen.height);

instead of Screen.width in your calculations (you'll need a to set the uiRoot reference to the UIRoot object in your scene).

Comment
Add comment · Show 1 · 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 Bigproblem01 · Jul 12, 2014 at 10:53 AM 0
Share

aaaaaand this fixes the issue. Thanks a lot man!

avatar image
0

Answer by Sisso · Jul 11, 2014 at 04:24 PM

In ngui 3 layout with multiples resolutions are very easy to do using unified system without any code.

In ngui you never use Screen.width and height if you are using UIRoot to scale your GUI. If your code is using it, probably, it is the problema. The reason that it only happens on mobile is because your UIRoot was configured to FixedSizeOnMobile

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 Bigproblem01 · Jul 11, 2014 at 11:08 PM 0
Share

No, my UIRoot is configured on FixedSize.

I don't quite understand what you're saying, do you mean to not use the resize function with code and just leave it as it is? If so then when I do that it doesn't even rescale properly in the engine : (

I need the bars to scale with the resolution and Anchors don't help with that, neither does UIStretch and I don't know what else I can do besides the code which in turn doesn't work :\

avatar image HolBol · Jul 11, 2014 at 11:08 PM 0
Share

Please use the comments section to respond to answers.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Autoscaling interface for iphone 3gs and iphone 4 0 Answers

Help finding the right scale for an icon inside a backgorund sprite 1 Answer

NGUI sprite size 1 Answer

Dynamic line-drawing between objects (nGUI) 1 Answer

IOS build with a smaller size 2 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