当需要判断某个编辑器菜单项是否可用时用以下方法:
严格按照以下的方法才生效,菜单路径必须一样,参数也需要和以下保存一致
[MenuItem("编辑器扩展/CreateUiRoot", true)]
static bool CreateWizardIsActive()
{
return !GameObject.Find("Canvas");
}
[MenuItem("编辑器扩展/CreateUiRoot", false, 10)]
static void CreatCanvas()
{
Debug.Log("CreatCanvas");
GameObject ui = new GameObject("Canvas");
ui.AddComponent<Canvas>().renderMode=RenderMode.ScreenSpaceOverlay;
ui.AddComponent<UnityEngine.UI.CanvasScaler>();
ui.AddComponent<UnityEngine.UI.GraphicRaycaster>();
}