I want to get the width and height of the UIWidget to get Rect like the unity GUI. It works on iPhone resolution but return the same width and height for iPad. I even tried scaling the width and height( see commented code
Rect GetRect()
{
UISprite sp = GetComponent<UISprite> ();
Vector3 pt = sp.transform.TransformPoint (sp.transform.position);
pt = UICamera.currentCamera.WorldToScreenPoint(pt);
//float width = (touchZone.width*NGUITools.screenSize.x)/touchZone.root.manualWidth;
//float height = (touchZone.height*NGUITools.screenSize.y)/touchZone.root.activeHeight;
Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(UICamera.currentCamera.transform, sp.transform);
float width = bounds.size.x;
float height = bounds.size.y;
Debug.LogError("Button Width:"+ width + " Height: " + height);
Rect rect
= new Rect
(pt
.x - width
/ 2, pt
.y - height
/ 2, width, height
); return rect;
}
This is my UIRoot setup is
Scaling style : Constrained on mobile
Content Widht: 1280 Fit: false
Content Height: 768 Fit: true