using System; using System.IO; using System.Text; using UnityEditor; using UnityEngine; using System.Reflection; namespace Thousandto.DIY { public class MyMenuItems { [MenuItem("Tool/添加button和boxcollider/")] public static void AddBoxcolliderAndButton() { var gos = Selection.gameObjects; for(int i = 0; gos != null && i < gos.Length; ++i) { GameObject go = gos[i]; UISprite sp = go.GetComponent(); if (sp == null) continue; sp.autoResizeBoxCollider = true; UIButton bt = go.GetComponent(); BoxCollider box = go.GetComponent(); if (bt == null) bt = go.AddComponent(); if (box == null) box = go.AddComponent(); sp.autoResizeBoxCollider = true; box.size = sp.localSize; } } } }