Author Topic: Bug - UICamera dimensions incorrectly calculated  (Read 7839 times)

BeShifty

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 7
  • Posts: 52
    • View Profile
Bug - UICamera dimensions incorrectly calculated
« on: July 11, 2014, 03:13:14 PM »
Bug: When the UI's camera is not a child of a UIRoot, its dimensions are reported as far too large.

Steps to Reproduce:
1) In an empty scene, run NGUI/Create/UI 2D
2) Unparent the Camera GameObject from the UI Root GameObject
3) Reset the Camera's transform.
Note that the Panel attached to the UIRoot now has a gigantic rect visualization, even though the Camera's frustum hasn't changed size at all. For further visualization of the issue, add a sprite as a child of the panel, and anchor it fully to the panel or the camera.

The issue I believe stems from the fact that in NGUITools.GetSides(Camera) and NGUITools.GetWorldCorners(Camera), the points are being transformed by cam.transform.TransformPoint, despite the fact that Unity doesn't scale cameras' frustums by their transform scale. I can hack it to work by modifying the aforementioned functions to something like I've attached below, but you probably need to fix the rectangle gizmos/handles as well.

  1. static public Vector3[] GetSides (this Camera cam, float depth, Transform relativeTo)
  2. {
  3.         Rect rect = cam.rect;
  4.         Vector2 size = screenSize;
  5.  
  6.         float x0 = -1f;
  7.         float x1 = 1f;
  8.         float y0 = -1f;
  9.         float y1 = 1f;
  10.  
  11.         float aspect = (size.x / size.y) * (rect.width / rect.height);
  12.         x0 *= aspect;
  13.         x1 *= aspect;
  14.        
  15.         mSides[0] = new Vector3(x0, 0f, depth);
  16.         mSides[1] = new Vector3(0f, y1, depth);
  17.         mSides[2] = new Vector3(x1, 0f, depth);
  18.         mSides[3] = new Vector3(0f, y0, depth);
  19.         if (relativeTo != null)
  20.         {
  21.                 for (int i = 0; i < 4; ++i)
  22.                         mSides[i] = relativeTo.InverseTransformPoint(mSides[i]);
  23.         }
  24.         return mSides;
  25. }
  26.  

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Bug - UICamera dimensions incorrectly calculated
« Reply #1 on: July 11, 2014, 07:02:05 PM »
This is fixed in the newest version on the pro repo. It'll be out with the next update.

htx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Bug - UICamera dimensions incorrectly calculated
« Reply #2 on: July 14, 2014, 06:24:46 AM »
Hi, i just upgraded from 3.6.5 to 3.6.8 and this happened to me with a 3d ui.
Also tested with a new scene as op described. It resizes the uiroot to a very large region.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug - UICamera dimensions incorrectly calculated
« Reply #3 on: July 15, 2014, 12:28:28 AM »
Then you don't have 3.6.8. Double-check your version. (Help -> NGUI Documentation v.3.6.X).

htx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Bug - UICamera dimensions incorrectly calculated
« Reply #4 on: July 15, 2014, 05:20:36 AM »
Yea, it's 3.6.8 for sure. Can reproduce it everytime. Don't even have to mess with the camera.
1. create 3dui in 3.6.5.
2. anchor sprite to the top left
3. upgrade to 3.6.8
-> sprite moved out of camera view to the new gigantic uiroot top left corner

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug - UICamera dimensions incorrectly calculated
« Reply #5 on: July 15, 2014, 08:48:56 PM »
Wait... 3D UI? Anchors only work with 2D UIs, not 3D. I do see that the bounds of the panel are quite a bit off with 3D UIs though. I'll fix that.

Edit: Fixed in the Pro repository, so you will find it in the next update. As a nice side-effect, the layout system's anchoring will now work with 3D UIs.
« Last Edit: July 15, 2014, 09:32:37 PM by ArenMook »

htx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Bug - UICamera dimensions incorrectly calculated
« Reply #6 on: July 17, 2014, 06:55:55 AM »
Nice, thank you. Looking forward to it.