A game about forced loneliness, made by TACStudios
at master 2.7 kB view raw
1using PlasticGui; 2using System; 3using System.Reflection; 4using UnityEditor; 5using UnityEngine; 6 7namespace Unity.PlasticSCM.Editor.UI 8{ 9 internal static class HandleMenuItem 10 { 11 internal static void AddMenuItem( 12 string name, 13 int priority, 14 Action execute, 15 Func<bool> validate) 16 { 17 AddMenuItem(name, string.Empty, priority, execute, validate); 18 } 19 20 internal static void AddMenuItem( 21 string name, 22 string shortcut, 23 int priority, 24 Action execute, 25 Func<bool> validate) 26 { 27 MethodInfo InternalAddMenuItem = MenuType.GetMethod( 28 "AddMenuItem", 29 BindingFlags.Static | BindingFlags.NonPublic); 30 31 if (InternalAddMenuItem == null) 32 { 33 Debug.LogWarningFormat( 34 PlasticLocalization.GetString( 35 PlasticLocalization.Name.ErrorAddPlasticSCMMenuItem), 36 name); 37 return; 38 } 39 40 InternalAddMenuItem.Invoke( 41 null, new object[] { 42 name, shortcut, false, 43 priority, execute, validate }); 44 } 45 46 internal static void RemoveMenuItem(string name) 47 { 48 MethodInfo InternalRemoveMenuItem = MenuType.GetMethod( 49 "RemoveMenuItem", 50 BindingFlags.Static | BindingFlags.NonPublic); 51 52 if (InternalRemoveMenuItem == null) 53 { 54 Debug.LogWarningFormat( 55 PlasticLocalization.GetString( 56 PlasticLocalization.Name.ErrorRemovePlasticSCMMenuItem), 57 name); 58 return; 59 } 60 61 InternalRemoveMenuItem.Invoke( 62 null, new object[] { name }); 63 } 64 65 internal static void UpdateAllMenus() 66 { 67 MethodInfo InternalUpdateAllMenus = EditorUtilityType.GetMethod( 68 "Internal_UpdateAllMenus", 69 BindingFlags.Static | BindingFlags.NonPublic); 70 71 if (InternalUpdateAllMenus == null) 72 { 73 Debug.LogWarning( 74 PlasticLocalization.GetString( 75 PlasticLocalization.Name.ErrorUpdatePlasticSCMMenus)); 76 return; 77 } 78 79 InternalUpdateAllMenus.Invoke(null, null); 80 } 81 82 internal static bool GetEnabled(string menuPath) 83 { 84 return Menu.GetEnabled(menuPath); 85 } 86 87 static readonly Type MenuType = typeof(UnityEditor.Menu); 88 static readonly Type EditorUtilityType = typeof(UnityEditor.EditorUtility); 89 } 90}