- Home /
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.
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.
Hey bchilds88, Thanks for this. I'm still learning all this stuff. I'll try it out. Best...
if you have any other question just ask. I have a lot more scripts that deal with resolution sizing.
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
}
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.
No problem man! :) If this was helpful to you please mark the answer as correct so others can benefit from it!
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.
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
Follow this Question
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