Article directory
1. The desired effect
2. Create an Edit folder under Unity's Assets folder, and create a class that modifies MenuItem under this folder
3. Use [MenuItem("XXXX")] to create the top bar menu
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;//需要使用UnityEditor的类
using UnityEngine;
//Unity顶部菜单自定义修改
public class MyMenu
{
//使用MenuItem来修改顶部菜单(%指ctrl|#指shift|&指alt)
[MenuItem("MyMenu/Menu_01/Test_01 %#&1")]
static void MyMenu1_Text01() {
Debug.Log("你测试了菜单1");
}
[MenuItem("MyMenu/Menu_01/Test_02 %#&2")]
static void MyMenu1_Text02()
{
Debug.Log("你测试了菜单2");
}
[MenuItem("MyMenu/Menu_02/Test_03 %#&3")]
static void MyMenu2_Text01() {
Debug.Log("你测试了菜单3");
}
[MenuItem("MyMenu/Menu_02/Test_04 %#&4")]
static void MyMenu2_Text02() {
Debug.Log("你测试了菜单4");
}
}
Summarize
Use MenuItem in the class under the Edit file under the Unity resource folder to modify the top menu bar