[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");
}