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 JeffreyD · Oct 31, 2013 at 08:03 PM · androidmobilescreennguiapp

How do I config NGUI screen to fit Mobile device?

Hello, I'm creating an app for Android and eventually iPhone. I;m using NGUI. I can see the app running on my Android (Samsung S4 1920x1080). I've sized the app in Unity to be 320x480. When I run the app using unity remote it appears stretched on the Android screen. Can any one help me fix this, so I can run my app on any device Andriod or IPhone? Thanks for you help.

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
0
Best Answer Wiki

Answer by Triqy · Nov 10, 2013 at 03:06 PM

The way i achieved this is by getting the screen resolution of the device and scaling the GUI to fit that specific screen per device...

 var ScreenRES_Width: float;
 var ScreenRES_Height: float;
 
 function Start(){

 AutoSizeScreen();

 }


 function AutoSizeScreen(){
 ScreenRES_Width = Screen.width;
 ScreenRES_Height = Screen.height;
 
 if(ScreenRES_Width < 800 && ScreenRES_Height < 480){
 
 PlayButtonGUI.DetectSmallScreen();
 OptionsButtonGUI.DetectSmallScreen();
 ExitButtonGUI.DetectSmallScreen();
 
 }else if(ScreenRES_Width == 800 && ScreenRES_Height == 480 ){
 
 PlayButtonGUI.DetectMediumScreen();
 OptionsButtonGUI.DetectMediumScreen();
 ExitButtonGUI.DetectMediumScreen();
 
 }else{
 
 //PlayButtonGUI.DetectLargeScreen();
 //OptionsButtonGUI.DetectLargeScreen();
 //ExitButtonGUI.DetectLargeScreen();
 //BackButtonGUI.DetectLargeScreen();
 
 PlayButtonGUI.DetectMediumScreen();
 OptionsButtonGUI.DetectMediumScreen();
 ExitButtonGUI.DetectMediumScreen();
 BackButtonGUI.DetectMediumScreen();
 }
 
 //Debug Purposes ( Can Delete at a later date when not needed)** ( DELETE WHEN DONE!!!!)
 TempResW = Screen.width;
 TempResH = Screen.height;
 //***********************************************************************************
 }


of course this script is referencing 4 other CUSTOM GUIs i have made to fit the size of different screens for different devices.

this is code straight from one of my own scripts. nothing was edited. the point is that you have to find the screen res by finding the height and width and then mold your GUI pixelinset accordingly.

Comment
Add comment · Show 5 · 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 JeffreyD · Nov 10, 2013 at 03:21 PM 0
Share

Hey bchilds88, Thanks for this. I'm still learning all this stuff. I'll try it out. Best...

avatar image Triqy · Nov 10, 2013 at 03:37 PM 0
Share

if you have any other question just ask. I have a lot more scripts that deal with resolution sizing.

avatar image Triqy · Nov 10, 2013 at 03:53 PM 0
Share

The part you probably need to considerate on is

 Screen.height 

and

 Screen.width

maybe something like this in JS

 static var myScreenHeight: float;
 static var myScreenWidth: float;
 
 function Start(){
 
 //finding your device res.
 
 myScreenHeight = Screen.height;
 myScreenWidth  = Screen.width;
 
 //note: this will either find the editors or you devices resolution. 
 
 //this will be on your "Game $$anonymous$$anager" Object
 
 }


After you got that; you have to create your GUIs and use a series of if statments like : ( this is in your GUI Script!!)

 if(Game$$anonymous$$anagerScript.myScreenHeight < 1024 && Game$$anonymous$$anagerScript.myScreenWidth < 800){
 
 //Set your GUIs **pixelinset** here for sizing to the correct //screen size
 
 }
avatar image JeffreyD · Nov 10, 2013 at 06:02 PM 0
Share

Wow, thanks for all this. I'm doing a lot with NGUI (or trying to learn how to use NGUI). Since I'm still in learning mode with both UNITY and NGUI I'm finding it difficult to understand what is possible with the regular GUI vs NGUI or even NGUI by itself. Perhaps I need to learn more about doing my own scripting ins$$anonymous$$d of what is available through NGUI.

I suppose I could write the script to have my UI display be a standard size if it falls within the resolution of the given devices screen as apposed to "fitting" it into the available resolution. If I "fit it in" the available resolution won't my UI get stretched?

I'll play with all of this once school ends in $$anonymous$$id December. So, I'll probably post again around Christmas time. Thanks again.

avatar image Triqy · Nov 10, 2013 at 06:07 PM 0
Share

No problem man! :) If this was helpful to you please mark the answer as correct so others can benefit from it!

avatar image
0

Answer by JeffreyD · Oct 31, 2013 at 09:24 PM

I just got the app loaded into my Android Via USB and ATP (Android File Transfer) and running. It runs but it's over sized for the screen. I only see a portion of the app. What do I need to do to fix? Thanks.

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 JeffreyD · Nov 10, 2013 at 02:51 PM 0
Share

Found a nice discussion of this at http://www.tasharen.com/forum/index.php?topic=1398.0

Hope it helps someone that has a similar issue to $$anonymous$$e.

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

16 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

Related Questions

How do I make on screen buttons in Android? 4 Answers

Huawei P20 Pro Safe Area Issue 1 Answer

How do I reset Screen.sleepTimeout's user input timer? 1 Answer

Android Game not working 2 Answers

Detect Device Orientation Event 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