[MenuItem("GameObject/3D Object/创建为预置")]
static void CreatePrefab() //创建预设的方法
{
GameObject go = Selection.activeGameObject;
if(go==null)
{
Debug.LogError("没有选中游戏对象");
return;
}
PrefabUtility.CreatePrefab(string.Format("Assets/{0}.prefab", go.name), go);
AssetDatabase.Refresh();
}
[MenuItem("Assets/编辑选中的prefab")]
static void EditorPrefab()//删除子对象中第一个组件带有BoxCollider的BoxCollider属性
{
GameObject go = Selection.activeGameObject;
if (go == null)
{
Debug.LogError("没有选中游戏对象");
return;
}
go.transform.position = UnityEngine.Vector3.zero;
BoxCollider bc = go.GetComponentsInChildren<BoxCollider>(true)[0];
if(bc)
{
Object.DestroyImmediate(bc,true);
}
EditorUtility.SetDirty(go);
}
//自定义菜单执行想要执行的操作
[MenuItem("MyControl/command")]
static void Test()
{
EditorApplication.ExecuteMenuItem("GameObject/3D Object/创建为预置");
EditorApplication.ExecuteMenuItem("GameObject/Create Empty");
}