Unity - MenuItem Features

MenuItem(string itemName, bool isValidateFunction, int priority)

Parameter 1: menu name

Parameter 2: Whether to use custom conditions to control whether the menu item can be clicked, the default is false, generally no value is assigned, if necessary, two MenuItems need to be defined

        MenuItem 1 : Whether the custom condition controls whether the menu is clickable, and the function needs to return a bool value

        MenuItem 2 : click callback

        

        

 Parameter 3: Menu item display priority, the smaller the value, the higher the value

                Special Note: When there is a multi-level submenu, the priority of the parent menu depends on the "priority specified by the submenu item when the menu is defined for the first time",

                This means that when the priority of submenu items is subsequently changed, only the display order of submenu items will be affected, and the priority of the parent menu will no longer be changed

                If you want to reset the priority of the parent menu, you can comment out the definition of MenuItem first, wait for Unity to compile, then uncomment it, and let Unity recompile

Optional menu:

	[MenuItem("工具/Toggle菜单/Toggle1", priority = 7000)]
		public static void MenuToggle1()
		{
			var menuPath = "工具/Toggle菜单/Toggle1";
			var isOn = Menu.GetChecked(menuPath);
			Menu.SetChecked(menuPath, !isOn);
		}
		[MenuItem("工具/Toggle菜单/Toggle2", priority = 7000)]
		public static void MenuToggle2()
		{
			var menuPath = "工具/Toggle菜单/Toggle2";
			var isOn = Menu.GetChecked(menuPath);
			Menu.SetChecked(menuPath, !isOn);
		}
		[MenuItem("工具/Toggle菜单/Toggle3", priority = 7000)]
		public static void MenuToggle3()
		{
			var menuPath = "工具/Toggle菜单/Toggle3";
			var isOn = Menu.GetChecked(menuPath);
			Menu.SetChecked(menuPath, !isOn);
		}

おすすめ

転載: blog.csdn.net/smile_otl/article/details/132460500
おすすめ