版本:Unity 6 (6000.0)
语言中文
  • C#

Menu.GetChecked

建议更改

成功!

感谢您帮助我们提升 Unity 文档的质量。尽管我们无法接收全部提交,但我们确实会阅读用户提出的每一项建议性更改,并在适用时进行更新。

关闭

提交失败

由于某些原因,您的建议性更改无法提交。请在几分钟后<a>重试</a>。感谢您抽出时间帮助我们提升 Unity 文档的质量。

关闭

取消

声明

public static bool GetChecked(string menuPath);

说明

获取菜单项的选中状态。

    using UnityEditor;
    using UnityEngine;

public class CheckMenuTest: MonoBehaviour { // Add a menu item named "MenuTest" to MyMenu in the main menu. [MenuItem("MyMenu/MenuTest")] static void DoSomething() { Debug.Log("A placeholder menu item."); } // Add a menu item that you can click to add a check to the "MenuTest" menu item in MyMenu in the main menu. [MenuItem("MyMenu/Check menu item")] static void CheckMenu() { Menu.SetChecked("MyMenu/MenuTest", true); Debug.Log("Checked 'MenuTest'"); } // Add a menu item that you can click to clear the check from the "MenuTest" menu item in MyMenu in the main menu. [MenuItem("MyMenu/Clear check from menu")] static void ClearCheck() { Menu.SetChecked("MyMenu/MenuTest", false); Debug.Log("Cleared check from menu"); }

// Add a menu item that you can click to determine if the "MenuTest" in the main menu is checked. [MenuItem("MyMenu/Is MenuTest checked?")] static void GetChecked() { if (Menu.GetChecked("MyMenu/MenuTest")) { Debug.Log("MenuTest is checked"); } else { Debug.Log("MenuTest is not checked"); } } }