Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rinesh

Pages: [1]
1
NGUI 3 Support / UIWidget width and height
« on: October 03, 2016, 01:53:29 AM »
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

                 
  1.  Rect GetRect()
  2.       {
  3.          UISprite sp = GetComponent<UISprite> ();
  4.          Vector3 pt = sp.transform.TransformPoint (sp.transform.position);
  5.          pt = UICamera.currentCamera.WorldToScreenPoint(pt);
  6.  
  7.          //float width = (touchZone.width*NGUITools.screenSize.x)/touchZone.root.manualWidth;
  8.          //float height = (touchZone.height*NGUITools.screenSize.y)/touchZone.root.activeHeight;
  9.          
  10.          Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(UICamera.currentCamera.transform, sp.transform);
  11.          float width = bounds.size.x;
  12.          float height = bounds.size.y;
  13.  
  14.          Debug.LogError("Button Width:"+ width + " Height: " + height);
  15.          Rect rect = new Rect(pt.x - width / 2, pt.y - height / 2, width, height);
  16.          return rect;
  17.       }

This is my UIRoot setup is
Scaling style : Constrained on mobile
Content Widht: 1280  Fit: false
Content Height: 768   Fit: true


Pages: [1]