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.
static public Vector3[] GetSides (this Camera cam, float depth, Transform relativeTo)
{
Rect rect = cam.rect;
Vector2 size = screenSize;
float x0 = -1f;
float x1 = 1f;
float y0 = -1f;
float y1 = 1f;
float aspect = (size.x / size.y) * (rect.width / rect.height);
x0 *= aspect;
x1 *= aspect;
mSides
[0] = new Vector3
(x0, 0f, depth
); mSides
[1] = new Vector3
(0f, y1, depth
); mSides
[2] = new Vector3
(x1, 0f, depth
); mSides
[3] = new Vector3
(0f, y0, depth
); if (relativeTo != null)
{
for (int i = 0; i < 4; ++i)
mSides[i] = relativeTo.InverseTransformPoint(mSides[i]);
}
return mSides;
}