Author Topic: UIRoot  (Read 60107 times)

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIRoot
« Reply #15 on: September 18, 2014, 06:07:24 PM »
I am seriously confused at this point. I haven't done any work with NGUI for some time and just upgraded to 3.7.2, and nothing seems as it used to be, and I'm lost…

When I create a new 2D GUI it creates a UIRoot with an attached camera, which is fine. However, the red rectangle representing the camera view is ridiculously small, using up, only about a quarter of the width of the actual screen/scene. Why is that? Am I missing something?

I am using one fullscreen scene, representing a 2D screen in the game, so nothing is scrolling etc. Ideally, it would be helpful if the UI placement would actually match the backdrop in terms of size and positions. As it stands right now, I have place the UI elements in places that have no actual relationship to the game screen itself, and it is impossible to place them in code, because the object positions follow an entirely different scale than those of the actual game graphics. The way it is currently, is really quite unusable, but I found no way to fix this.

What am I doing wrong? How can I get NGUI to create a user interface that matches the scale and placement of the scene it belongs to, so that it's not entirely disjointed?

Thanks for any suggestions.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRoot
« Reply #16 on: September 19, 2014, 08:54:22 PM »
I'm not sure what you mean. Red rectangle? Do you mean the maroon one? That's the bounds of the panel. By default it will match the bounds of the screen, assuming the UI camera is left at its default size of 1, and you didn't get layers wrong. Make sure that all cameras have proper layers set. Your UI camera should only see the UI layer, and your other cameras should not see the UI layer.

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIRoot
« Reply #17 on: September 21, 2014, 06:34:28 PM »
It's not maroon. It's bright red. Enclosed is a screenshot for you to look at. I've noticed that the red box changes depending on how I adjust the "Game" screen window, but no matter what I do, it never matches up with the actual size of the scene. Keep in mind that my scene is supposed to be a single-screen entity. Think of it as a menu screen that does not scroll or move or anything.

With the current set up it is virtually impossible to place or control UI elements because they have to be placed on positions that have absolutely no relation to the actual scene positions, not to mention that they will all clutter up there in the small rectangle in the center of the screen, obscuring whatever else is supposed to be there in the scene view.

I hope it's a bit clearer now.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: UIRoot
« Reply #18 on: September 22, 2014, 08:18:01 AM »
I'm a bit confused with the new UI root scaling. I am using a 3D UI in Constrained mode with height set to 1080 and fit option enabled for it.

Despite that setting, I'm actually getting 2629x1478 pixel area (measured by anchoring a sprite to UIRoot object dimensions). Experimenting with UIRoot further, I found it impossible to actually change that 1478px height with any UIRoot configuration - the only thing that changes is UIRoot transform scale and (if I switch the screen from 16:9 to free aspect and and drag the proportions around) pixel area width, but never the height, no matter what I use (Constrained or Flexible, fitted or not, any resolution in any field). What am I missing?

Edit: Aha, I see it depends on the 3D camera Z distance from the origin. That distance is not directly translated to pixel area height, though: you get 1478 vertical pixels from the camera situated at -1536, and that proportion (1.03924221922) is not really ringing any bells to me. I have just checked the default 3D UI prefab, and the camera Z offset is set to 700 there, which translates to pixel area height of 810, which is again completely incorrect (for default UIRoot fit height setting of 720 pixels). The size also depends on FOV of the camera. I'd expect one of those parameters to be directly controlled by UIRoot depending on selected resolution, but nothing actually happens with them no matter what you input into UIRoot.

What's going wrong here?
« Last Edit: September 22, 2014, 08:42:17 AM by bac9 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRoot
« Reply #19 on: September 22, 2014, 10:44:23 AM »
Yeah the 3D cameras make it really difficult to draw the outline correctly. I suggest you stick to 2D cameras unless you really have to use a 3D one. If you do use a 3D one, the outline is not likely to be of any help to you.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: UIRoot
« Reply #20 on: September 22, 2014, 11:13:49 AM »
So, if I understand correctly, there is no way to directly influence the resolution of pixel area through UIRoot when you are using a 3D camera, with scaling options having no effect unless you are using a 2D camera?

It might be a good idea to communicate that in the UIRoot inspector hints then :)

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIRoot
« Reply #21 on: September 22, 2014, 06:34:22 PM »
Thanks for the thought, ArenMook… I'm not sure I understand, though. What is a 2D camera, or rather how would I create it? I can only find one type of camera in Unity, and in my scene I have the 2D toggle switched on. What am I missing?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRoot
« Reply #22 on: September 23, 2014, 12:47:27 PM »
2D camera is a camera set to "Orthographic" mode. 3D camera is it set to "Perspective". By default NGUI always crates a layout with a 2D camera, unless you explicitly choose to create a 3D one via the menu.

StridingDragon

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIRoot
« Reply #23 on: September 23, 2014, 03:57:53 PM »
In that case my main camera is a 2D camera. However, comparing the cameras, I noticed that I had my main camera set to a size of 5, which created the discrepancy. Once I set my NGUI camera to 5 as well, everything is as it should be. Problem solved!  :D

Thanks so much for the help, ArenMook

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: UIRoot
« Reply #24 on: October 29, 2014, 01:08:49 AM »
How to change Scaling Style by code ?
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRoot
« Reply #25 on: October 29, 2014, 05:37:46 AM »
UIRoot.scalingStyle

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: UIRoot
« Reply #26 on: October 30, 2014, 11:36:59 PM »
Aren , could you help to me pls, i have a trouble.

If i build for ios with game screen size 1024*768 and run on iphone 5s, moving anchored widgets are displaying not so good (vertical crop), i mean wrong position not same on unity game screen, as if i run this builded app on a ipad 2mini anchored widgets are displaying good (moving to right positions) as i see on unity game screen. Even i set UIRoot manualWidth by code . if i set screen game size in unity to 1136*640 , build and run on iphone 5s everything are looking good, but if run on ipad 2mini that looking not so good (vertical crop). Don't understand this system, bcoz if i change game screen size in unity , always everything are looking good.
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIRoot
« Reply #27 on: November 01, 2014, 08:11:52 AM »
Anchors must be set to update OnUpdate if you are moving them or changing anything at run-time. Also depending on how you move them, if you use tweens it won't work as expected because tweens remember the starting position, which may be prior to anchor update.

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: UIRoot
« Reply #28 on: November 02, 2014, 07:52:19 AM »
You're right ArenMook. But if i'll use OnUpdate , it makes unmovable widget objects by tween.now i just hardcoded positions of widget objects depends on platform.

Thanks ArenMook.
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.