Author Topic: ngui - different resolution  (Read 21905 times)

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
ngui - different resolution
« on: November 28, 2012, 03:10:20 PM »
I wanted to react to my old topic but it was locked..

last time you said
"You can adjust the UIRoot's scale yourself by leaving it on 'manual' and writing a small script. If you want it to be based on width instead of height, or the largest of the two, then you can do just that."

that is exactly what I want , scale based on the largest of the two(instead of only vertical).
Now I know how to script in java, but I have no idea how to write this so it works in nGui and where to put this code?
if you could you tell me, i suspect its only 2 lines, and where to paste or put this script that would be really really great.

if not please give me some hints and I will try it myself
pretty pleaaasee  ;D.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ngui - different resolution
« Reply #1 on: November 29, 2012, 07:52:05 AM »
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UIRoot))]
  4. public class UIRootAdjustment : MonoBehaviour
  5. {
  6.         public int targetHeight = 720;
  7.  
  8.         UIRoot mRoot;
  9.  
  10.         void Awake () { mRoot = GetComponent<UIRoot>(); }
  11.  
  12.         void Update ()
  13.         {
  14.                 if (Screen.width > Screen.height)
  15.                 {
  16.                         mRoot.manualHeight = targetHeight;
  17.                 }
  18.                 else
  19.                 {
  20.                         mRoot.manualHeight = Mathf.RoundToInt(targetHeight * ((float)Screen.height / Screen.width));
  21.                 }
  22.         }
  23. }
« Last Edit: December 08, 2012, 11:45:04 PM by ArenMook »

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #2 on: November 30, 2012, 11:20:06 AM »
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UIRoot))]
  4. public class UIRootAdjustment : MonoBehaviour
  5. {
  6.         UIRoot mRoot;
  7.  
  8.         void Awake () { mRoot = GetComponent<UIRoot>(); }
  9.  
  10.         void Update ()
  11.         {
  12.                 if (Screen.width > Screen.height)
  13.                 {
  14.                         mRoot.manualHeight = Screen.height;
  15.                 }
  16.                 else
  17.                 {
  18.                         mRoot.manualHeight = Mathf.RoundToInt(Screen.height * ((float)Screen.height / Screen.width));
  19.                 }
  20.         }
  21. }

thanks so much!

the only problem is that the height now doesn't do anything.
the manual height actually changes when tweaking the screenheight, but it doesnt do anything(well it seems to want to, but bounces back, so the size stays the same and gets cut off, doesnt resize).
changing the width does work...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ngui - different resolution
« Reply #3 on: November 30, 2012, 01:57:16 PM »
Uncheck the "automatic" checkbox.

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #4 on: November 30, 2012, 02:05:40 PM »
Uncheck the "automatic" checkbox.

still the same..
when it's on the width doesn't do anything neither.
« Last Edit: November 30, 2012, 02:07:16 PM by wouter »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ngui - different resolution
« Reply #5 on: December 01, 2012, 10:53:33 AM »
Eh? I tested the code before I posted it here, and it works fine. Just keep in mind the game must be running before you resize the window.

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #6 on: December 04, 2012, 07:53:21 AM »
I test it twice...

I simply add the uiRootAdjustment script underneath the UIRoot, turn off automatic.

If i adjust the width things only scale after the width gets smaller than the height.
changing the height doesnt do anything...
(manual height on UIRoot does change, but its simply not rescaling.. when changing the height)
(as I said before it looks like it wants to rescale, it pops back and forth but stays the same size in the end)

----

When I dont add the script and turn off automatic, scaling the height works perfect.
I want the same type of scaling for the width, which would scale all the time, not only when width gets smaller dan height.. if thats possible.
if not the previous one is good as well I think, if it would work..  :P

But either way I can't get this too work...And I have tried many things but I cant get it to work..
Hope you can help me..

(I want one gui system that works on many different resolutions(portrait and landscape), since the sides get cut off I dont see how this is possible.. or ma i missing something?)
(Is it also possible to have different layout for portrait vs landscape which would change automatically)
« Last Edit: December 04, 2012, 08:00:11 AM by wouter »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ngui - different resolution
« Reply #7 on: December 04, 2012, 10:30:48 AM »
What version of NGUI do you have?

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #8 on: December 04, 2012, 11:21:13 AM »
Version 2.0.7c

I do have the free version at the moment, and plan to switch/buy for the final build.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ngui - different resolution
« Reply #9 on: December 05, 2012, 05:02:00 AM »
Free version is very old and is not supported. There have been numerous bug fixes since May when it was released.

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #10 on: December 05, 2012, 07:05:33 AM »
Free version is very old and is not supported. There have been numerous bug fixes since May when it was released.

ah well okey than I'll just buy it, was planning to anyway.
Will get back to you wether it worked or not.

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #11 on: December 08, 2012, 06:10:45 PM »
Well.. I baught Ngui from your website.

Still the same problem, scaling the width works, scaling the height of the screen does nothing(even though manual height on UIRoot changes, the sprite jumps around a little but stays the same size..)

weird thing is that when I turn of the UIRootAdjusment script and manually change the "manual height" it does scale..

What am I doin wrong here  ???
« Last Edit: December 08, 2012, 06:12:58 PM by wouter »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ngui - different resolution
« Reply #12 on: December 08, 2012, 11:44:46 PM »
I think I know what you mean. Try this one:
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UIRoot))]
  4. public class UIRootAdjustment : MonoBehaviour
  5. {
  6.         public int targetHeight = 720;
  7.  
  8.         UIRoot mRoot;
  9.  
  10.         void Awake () { mRoot = GetComponent<UIRoot>(); }
  11.  
  12.         void Update ()
  13.         {
  14.                 if (Screen.width > Screen.height)
  15.                 {
  16.                         mRoot.manualHeight = targetHeight;
  17.                 }
  18.                 else
  19.                 {
  20.                         mRoot.manualHeight = Mathf.RoundToInt(targetHeight * ((float)Screen.height / Screen.width));
  21.                 }
  22.         }
  23. }

wouter

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: ngui - different resolution
« Reply #13 on: December 09, 2012, 06:46:05 AM »
Yay it works  :D

Thanks for your help!

venkat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: ngui - different resolution
« Reply #14 on: August 09, 2013, 06:32:22 AM »
i Needed Menu Screens, i Have done This.But it Not Set For Width in All Resolutions Globally.So How to Solve this problem.
« Last Edit: August 09, 2013, 06:47:23 AM by venkat »