ScriptReference/EditorApplication.ExecuteMenuItem #214
Replies: 2 comments
-
|
Note you can find a list of all menu items by using the undocumented static int CalculateIndent(string source)
{
int spaceCount = 0;
for (int i = 0; i < source.Length; i++)
{
if (source[i] == ' ')
{
spaceCount++;
}
else
{
break;
}
}
return spaceCount / 4;
}
public static List<string> ParseMenuItems()
{
List<string> menuItemMappings = new List<string>();
string mainMenuString = EditorGUIUtility.SerializeMainMenuToString();
string[] split = mainMenuString.Split('\n');
int lastIndent = -1;
List<string> stack = new List<string>();
foreach (string line in split)
{
if (line.Trim().Length == 0) continue;
int newIndent = CalculateIndent(line);
for (int i = lastIndent; i < newIndent; i++)
{
stack.Add("");
}
for (int i = lastIndent; i > newIndent; i--)
{
stack.RemoveAt(stack.Count - 1);
}
stack[stack.Count - 1] = line.Trim();
string path = string.Join("/", stack.ToArray());
menuItemMappings.Add(path);
lastIndent = newIndent;
}
return menuItemMappings;
} |
Beta Was this translation helpful? Give feedback.
-
|
Note that from Unity 2018.2 almost all built in Window paths change, for example Window/Inspector becomes Window/General/Inspector. As such you may need to use #if UNITY_2018_2_OR_NEWER to branch the paths in your code if you need to support older versions of Unity. Selection.activeObject = KeyMappings.Instance;
EditorApplication.ExecuteMenuItem("Window/General/Inspector");This sets the scriptable object (or any object) as the selection then will either focus an inactive Inspector tab or create a new one if there isn't one already. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
ScriptReference/EditorApplication.ExecuteMenuItem
https://docs.unity3d.com/ScriptReference/EditorApplication.ExecuteMenuItem.html
Beta Was this translation helpful? Give feedback.
All reactions