Files
Main/Assets/Editor/DIY/FormTools/MenuItem.cs

36 lines
1005 B
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
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<UISprite>();
if (sp == null) continue;
sp.autoResizeBoxCollider = true;
UIButton bt = go.GetComponent<UIButton>();
BoxCollider box = go.GetComponent<BoxCollider>();
if (bt == null) bt = go.AddComponent<UIButton>();
if (box == null) box = go.AddComponent<BoxCollider>();
sp.autoResizeBoxCollider = true;
box.size = sp.localSize;
}
}
}
}