1
NGUI 3 Support / UIWidget 'auto-adjust to match' size for BoxCollider2D
« on: May 21, 2014, 11:57:42 AM »
Hi!
I tried to search this question but no results...
So, I can't find checkbox in UIWidget's inspector window, that will auto-resize attached BoxCollider2D automatically.
And as I understand, I'm not allowed to mix BoxColliders & BoxCollider2Ds under one UICamera on one Layer (for properly touches handling),
so I need to use only BoxCollider2D if I switch UICamera to Unity2D Event Type.
So is 'auto-adjust' for BoxCollider2D feature scheduled for furher updates? Or I need to use some workarounds or hacks?
Thank you!
Edit:
As for now, I found 'hack' solution:
1) Add UIWidget and BoxCollider components to some GameObject;
2) In UIWidget's inspector window will apear 'auto-adjust to match' checkbox. Set it to Checked.
3) Remove BoxCollider and then add BoxCollider2D.
4) Then add some code to UIWidget.cs:
5) Now our BoxCollider2D appears to be updated when UIWidget's dimensions change.
I tried to search this question but no results...
So, I can't find checkbox in UIWidget's inspector window, that will auto-resize attached BoxCollider2D automatically.
And as I understand, I'm not allowed to mix BoxColliders & BoxCollider2Ds under one UICamera on one Layer (for properly touches handling),
so I need to use only BoxCollider2D if I switch UICamera to Unity2D Event Type.
So is 'auto-adjust' for BoxCollider2D feature scheduled for furher updates? Or I need to use some workarounds or hacks?
Thank you!
Edit:
As for now, I found 'hack' solution:
1) Add UIWidget and BoxCollider components to some GameObject;
2) In UIWidget's inspector window will apear 'auto-adjust to match' checkbox. Set it to Checked.
3) Remove BoxCollider and then add BoxCollider2D.
4) Then add some code to UIWidget.cs:
- public void ResizeCollider ()
- {
- if (NGUITools.GetActive(this))
- {
- BoxCollider box = collider as BoxCollider;
- if (box != null) NGUITools.UpdateWidgetCollider(box, true);
- // ** Modified for BoxCollider2D
- else
- {
- var box2D = collider2D as BoxCollider2D;
- if (box2D == null)
- return;
- Vector3[] corners = localCorners;
- box2D.center = Vector3.Lerp(corners[0], corners[2], 0.5f);
- box2D.size = corners[2] - corners[0];
- }
- // **
- }
- }
5) Now our BoxCollider2D appears to be updated when UIWidget's dimensions change.
