public MenuActionData(string scriptPath) { var rawPath = scriptPath.Replace("\\", "/").Replace(k_MenuActionsFolder, "").Replace(".cs", ""); typeString = GetClassName(rawPath); path = Regex.Replace(rawPath, @"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $0"); MenuAction instance = null; try { type = ReflectionUtility.GetType("UnityEditor.ProBuilder.Actions." + typeString); instance = System.Activator.CreateInstance(type) as MenuAction; } catch { Log.Warning($"Failed generating menu item for {scriptPath}. File names must match class names.", "scriptPath"); } valid = instance != null; if (valid) { PropertyInfo hasMenuEntryProperty = typeof(MenuAction).GetProperty("hasFileMenuEntry", BindingFlags.NonPublic | BindingFlags.Instance); visibleInMenu = hasMenuEntryProperty != null && (bool)hasMenuEntryProperty.GetValue(instance, null); menuItemShortcut = instance.tooltip.shortcut; } }
static TooltipEditor() { s_ShowModeEnum = ReflectionUtility.GetType("UnityEditor.ShowMode"); s_ShowPopupWithModeMethod = typeof(EditorWindow).GetMethod( "ShowPopupWithMode", BindingFlags.NonPublic | BindingFlags.Instance); }
static ProGridsInterface() { // Current release for (int i = 0, c = ProGridsEditorTypeNames.Length; i < c && s_ProGridsType == null; i++) { s_ProGridsType = ReflectionUtility.GetType(ProGridsEditorTypeNames[i]); } }
/// <summary> /// Generate the [MenuItem()] body for a pb_MenuAction from it's script path. /// </summary> /// <param name="scriptPath"></param> /// <returns></returns> static string GenerateMenuItemFunctions(string scriptPath) { string action = scriptPath.Replace("\\", "/").Replace(k_MenuActionsFolder, "").Replace(".cs", ""); string category = GetActionCategory(action); string menu_priority = GetMenuPriority(category); string class_name = GetClassName(action); string pretty_path = Regex.Replace(action, @"(\B[A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $0"); StringBuilder sb = new StringBuilder(); object o = null; try { var type = ReflectionUtility.GetType("UnityEditor.ProBuilder.Actions." + class_name); o = System.Activator.CreateInstance(type); } catch { Log.Warning("Failed generating menu item for class: \"" + class_name + "\". File names must match class names."); return(""); } PropertyInfo hasMenuEntryProperty = typeof(MenuAction).GetProperty("hasFileMenuEntry", BindingFlags.NonPublic | BindingFlags.Instance); if (hasMenuEntryProperty == null || (bool)hasMenuEntryProperty.GetValue(o, null) == false) { return(""); } PropertyInfo tooltipProperty = typeof(MenuAction).GetProperty("tooltip"); string shortcut = tooltipProperty == null ? "" : GetMenuFormattedShortcut(((TooltipContent)tooltipProperty.GetValue(o, null)).shortcut); // VERIFY sb.Append("\t\t[MenuItem("); sb.Append("k_MenuPrefix + \""); sb.Append(pretty_path); sb.Append(" "); sb.Append(shortcut); sb.Append("\", true)]"); sb.AppendLine(""); sb.Append("\t\tstatic bool MenuVerify"); sb.Append(class_name); sb.AppendLine("()"); sb.AppendLine("\t\t{"); sb.Append("\t\t\t"); sb.Append(class_name); sb.Append(" instance = EditorToolbarLoader.GetInstance<"); sb.Append(class_name); sb.AppendLine(">();"); sb.AppendLine(@" return instance != null && instance.enabled; "); sb.AppendLine("\t\t}"); sb.AppendLine(""); // PERFORM sb.Append("\t\t[MenuItem("); sb.Append("k_MenuPrefix + \""); sb.Append(pretty_path); sb.Append(" "); sb.Append(shortcut); sb.Append("\", false, "); sb.Append(menu_priority); sb.Append(")]"); sb.AppendLine(""); sb.Append("\t\tstatic void MenuDo"); sb.Append(class_name); sb.AppendLine("()"); sb.AppendLine("\t\t{"); sb.Append("\t\t\t"); sb.Append(class_name); sb.Append(" instance = EditorToolbarLoader.GetInstance<"); sb.Append(class_name); sb.AppendLine(">();"); sb.AppendLine("\t\t\tif(instance != null)"); sb.AppendLine("\t\t\t\tUnityEditor.ProBuilder.EditorUtility.ShowNotification(instance.DoAction().notification);"); sb.AppendLine("\t\t}"); return(sb.ToString()); }