MenuItem(string itemName, bool isValidateFunction, int priority)
[MenuItem("一级菜单/二级菜单上/三级菜单")]
static void MenuOne()
{
//功能
}
[MenuItem("一级菜单/二级菜单下")]
static void MenuTwo()
{
//功能
}
符号 | 字符 |
---|---|
% | Ctr/Command |
# | Shift |
& | Alt |
LEFT/Right/UP/DOWN | 方向键 |
F1-F2 | F功能键 |
_g | 字母g |
[MenuItem("一级菜单/二级菜单上 #_A")]
static void MenuA()
{
Debug.Log("A");
}
[MenuItem("一级菜单/二级菜单中 %#_B")]
static void MenuB()
{
Debug.Log("B");
}
[MenuItem("一级菜单/二级菜单下 %&_C")]
static void MenuC()
{
Debug.Log("B");
}
//设置勾选状态
//Menu.SetChecked(string menuPath, bool isChecked)
//获取勾选状态
//Menu.GetChecked(string menuPath)
[MenuItem("一级菜单/二级菜单上 #_A")]
static void MenuA()
{
string menuPath = "一级菜单/二级菜单上 #_A";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("一级菜单/二级菜单中 %#_B")]
static void MenuB()
{
string menuPath = "一级菜单/二级菜单中 %#_B";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("一级菜单/二级菜单下 %&_C")]
static void MenuC()
{
string menuPath = "一级菜单/二级菜单下 %&_C";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("菜单路径名")]
static void 方法() { }
[MenuItem("菜单路径名"),true]
static void 验证方法()
{
return bool值; //返回true 改菜单启用
}
[MenuItem("一级菜单/二级菜单上")]
static void MenuA()
{
string menuPath = "一级菜单/二级菜单上";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("一级菜单/二级菜单中")]
static void MenuB()
{
string menuPath = "一级菜单/二级菜单中";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
EditorPrefs.SetBool("MenuCValidate", isChecked);
}
[MenuItem("一级菜单/二级菜单下")]
static void MenuC()
{
string menuPath = "一级菜单/二级菜单下";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("一级菜单/二级菜单下", true)]
static bool MenuCValidate()
{
bool flag = EditorPrefs.GetBool("MenuCValidate");
Menu.SetChecked("一级菜单/二级菜单中", flag);
return flag;
}
[MenuItem("一级菜单/二级菜单上", false, 3)]
static void MenuA()
{
string menuPath = "一级菜单/二级菜单上";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("一级菜单/二级菜单中", false, 2)]
static void MenuB()
{
string menuPath = "一级菜单/二级菜单中";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("一级菜单/二级菜单下", false, 1)]
static void MenuC()
{
string menuPath = "一级菜单/二级菜单下";
bool isChecked = !Menu.GetChecked(menuPath);
Menu.SetChecked(menuPath, isChecked);
}
[MenuItem("GameObject/二级菜单", false, 1)]
static void MenuA()
{
}
[MenuItem("Assets/二级菜单", false, 1)]
static void MenuA()
{
}
[MenuItem("CONTEXT/组件名/菜单名")]
static void 方法名(MenuCommand cmd)
{
//组件名 t = cmd.context as 组件名;
//对该组件进行操作
}
[MenuItem("CONTEXT/Transform/Reset功能")]
static void ClearTransformMenu(MenuCommand cmd)
{
Transform t = cmd.context as Transform;
t.position = Vector3.zero;
t.rotation = Quaternion.identity;
t.localScale = Vector3.zero;
GameObject obj = new GameObject();
obj.transform.parent = t.gameObject.transform;
}
AddComponentMenu(string menuName, int order)
menuName:菜单名路径
order:菜单项排序
[AddComponentMenu("自定义/Test", 1)]
public class Test : MonoBehaviour
{
}
ContextMenu(string itemName, bool isValidateFunction, int priority)
itemName:菜单名称
isValidateFunction:不写为false,true则点击菜单前就会调用
priority:菜单项显示排序 默认 1000000
[AddComponentMenu("自定义/Test", 1)]
public class Test : MonoBehaviour
{
[ContextMenu("添加空物体")]
public void AddGameObject()
{
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
transform.localScale = Vector3.zero;
GameObject obj = new GameObject();
obj.transform.parent = transform;
}
}