Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: lzt120 on September 10, 2014, 10:13:32 PM

Title: UIButton and autoResizeBoxCollider
Post by: lzt120 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 ?
Title: Re: UIButton and autoResizeBoxCollider
Post by: lzt120 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.             }