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:
if (mSprite != null)
{
UIWidget temp = gameObject.GetComponent<UIWidget>();
if (temp == null)
{
temp = gameObject.AddComponent<UIWidget>();
}
temp.width = mSprite.width;
temp.height = mSprite.height;
temp.autoResizeBoxCollider = true;
}
I wonder if this can be build in or any other ways ?