Author Topic: UIButton and autoResizeBoxCollider  (Read 1671 times)

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
UIButton and autoResizeBoxCollider
« on: September 10, 2014, 10:13:32 PM »
In my project, there are a lot of UIButton for the UI, but UIButton do not has the autoResizeBoxCollider and I need add one invisible widget to do so and insert the code as list in UIButton's OnInit funtion:
  1.  if (mSprite != null)
  2.         {
  3.             UIWidget temp = gameObject.GetComponent<UIWidget>();
  4.             if (temp == null)
  5.             {
  6.                 temp = gameObject.AddComponent<UIWidget>();
  7.             }
  8.             temp.width = mSprite.width;
  9.             temp.height = mSprite.height;
  10.             temp.autoResizeBoxCollider = true;
  11.         }
I wonder if this can be build in or any other ways ?

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: UIButton and autoResizeBoxCollider
« Reply #1 on: September 10, 2014, 10:29:26 PM »
And this is the code for UICreateWidgetWizard to create button
  1.   UIWidget btnWidget = go.GetComponent<UIWidget>();
  2.             if (btnWidget == null)
  3.             {
  4.                 btnWidget = go.AddComponent<UIWidget>();
  5.                 btnWidget.autoResizeBoxCollider = true;
  6.                 btnWidget.width = bg.width;
  7.                 btnWidget.height = bg.height;
  8.             }