55using UnityEditor ;
66using UnityEngine ;
77using UnityEngine . UIElements ;
8- using static UnityEditor . PlayerSettings ;
98
109namespace GBG . AssetQuickAccess . Editor
1110{
@@ -47,7 +46,7 @@ public static List<string> GetAllMenuItemPaths()
4746 List < string > menuPaths = TypeCache . GetMethodsWithAttribute < MenuItem > ( )
4847 . SelectMany ( method => method . GetCustomAttributes < MenuItem > ( ) )
4948 . Where ( attr => attr . validate == false )
50- . Select ( attr => RemoveShortcut ( attr . menuItem ) )
49+ . Select ( attr => RemoveShortcutSymbols ( attr . menuItem ) )
5150 . Distinct ( )
5251 . ToList ( ) ;
5352 //string[] menuPaths = AppDomain.CurrentDomain.GetAssemblies()
@@ -62,17 +61,31 @@ public static List<string> GetAllMenuItemPaths()
6261 return menuPaths ;
6362 }
6463
65- // TODO: 移除快捷键符号!!
66- public static string RemoveShortcut ( string menuPath )
64+ public static string RemoveShortcutSymbols ( string menuPath )
6765 {
6866 // https://docs.unity3d.com/ScriptReference/MenuItem.html
6967 //%: Represents Ctrl on Windows and Linux. Cmd on macOS.
7068 //^: Represents Ctrl on Windows, Linux, and macOS.
7169 //#: Represents Shift.
7270 //&: Represents Alt.
71+ menuPath = menuPath . TrimEnd ( ) ;
72+ int lastIndexOfSpace = menuPath . LastIndexOf ( ' ' ) ;
73+ if ( lastIndexOfSpace == - 1 )
74+ {
75+ return menuPath ;
76+ }
7377
74- Debug . LogError ( "TODO: RemoveShortcut" ) ;
78+ char firstShortcutChar = menuPath [ lastIndexOfSpace + 1 ] ;
79+ if ( firstShortcutChar != '%' &&
80+ firstShortcutChar != '^' &&
81+ firstShortcutChar != '#' &&
82+ firstShortcutChar != '&' )
83+ {
84+ //Debug.LogError($"[Asset Quick Access] Failed to remove shortcut symbols from menu path: {menuPath}");
85+ return menuPath ;
86+ }
7587
88+ menuPath = menuPath . Substring ( 0 , lastIndexOfSpace ) . TrimEnd ( ) ;
7689 return menuPath ;
7790 }
7891
@@ -318,7 +331,7 @@ private void TrySubmit()
318331 int slashIndex = menuPath . LastIndexOf ( '/' ) ;
319332 if ( slashIndex > - 1 )
320333 {
321- menuName = menuPath . Substring ( slashIndex ) ;
334+ menuName = menuPath . Substring ( slashIndex + 1 ) ;
322335 }
323336
324337 SubmitMenuItem ( menuPath , menuName ) ;
0 commit comments