- Home /
How does the priority of a Editor menuItem change item placement?
Referring to the MenuItem.MenuItem static function; According to the scripting reference manual, "Priority defines the order by which menu items are displayed in the menu bar.". Testing it with the following code does not seem to have any impact on the placement of the menu item.
public class MenuExtensions : MonoBehaviour {
[MenuItem ("File/LalaLand", false, 0)]
static void ColladaExtract() {
Debug.Log("Doing extraction!");
}
}
Thanks!
Answer by Jake-L · Mar 12, 2011 at 06:08 PM
This is what I found out while working with custom menus:
The MenuItem's are sorted in increasing order and if you add more then 10 between two items, an Separator-Line is drawn before the menuitem.
For example, see Unity's GameObject menu (I stripped syntax to just itemName,Priority):
- GameObject/CreateEmpty,0
- GameObject/Create Other/Particle System,1
- GameObject/Create Other/Camera,2
- GameObject/Center On Children/15
Cheers Jake
Good sleuthing. I've also noticed that in the GameObject menu, priority -1000 puts items at the front (no surprise), and +1000 puts them at the end on the menu bar, but makes them disappear from the context menu. To complicate testing, the order may not be refreshed when code is recompiled, I need to close and reopen Unity to see the changes.
Great thanks to yoyo! It should be point out especially that the order may not be refreshed when code is recompiled, one need to close and reopen Unity to see the changes!
O$$anonymous$$G. Unbelievable. I can't believable that Unity Editor has that bug. I reopen Unity and it works like a charm. Thank zwcloud!
Answer by Reapazor · Dec 14, 2010 at 04:32 AM
It groups similar numbers together, and it appears that those are relative to increments of 50.
0 1 2 3
50 51 52 53
Answer by Jessy · Dec 01, 2010 at 07:13 PM
Unfortunately, it doesn't work (yet). I reported this bug on Christmas Eve of last year, and it's still open.
(Case 309855)
Answer by lidapow · Sep 23, 2011 at 06:18 AM
Works
@MenuItem("EventEditor/New", true)
static function FileNew () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/New", false, 10)
static function FileNewPerform () {
Debug.Log("Load");
}
@MenuItem("EventEditor/Open", true)
static function FileOpen () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Open", false, 11)
static function FileOpenPerform () {
Debug.Log("Save");
}
@MenuItem("EventEditor/Save", true)
static function FileSave () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Save", false, 30)
static function FileSavePerform () {
Debug.Log("Load");
}
@MenuItem("EventEditor/Save As", true)
static function FileSaveAs () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Save As", false, 30)
static function FileSaveAsPerform () {
Debug.Log("Load");
}
@MenuItem("EventEditor/Add/Entry", true)
static function AddEntry () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Add/Entry")
static function AddEntryPerform () {
EventEditorWindow.window.CallbackPopup(0, ["Add", "Remove"]);
}
@MenuItem("EventEditor/Add/Trigger", true)
static function AddTrigger () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Add/Trigger")
static function AddTriggerPerform () {
EventEditorWindow.window.CallbackPopup(1, ["Add", "Remove"]);
}
@MenuItem("EventEditor/Add/Terminal", true)
static function AddTerminal () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Add/Terminal")
static function AddTerminalPerform () {
EventEditorWindow.window.CallbackPopup(2, ["Add", "Remove"]);
}
Answer by lidapow · Sep 23, 2011 at 06:18 AM
It works
@MenuItem("EventEditor/New", true)
static function FileNew () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/New", false, 10)
static function FileNewPerform () {
Debug.Log("Load");
}
@MenuItem("EventEditor/Open", true)
static function FileOpen () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Open", false, 11)
static function FileOpenPerform () {
Debug.Log("Save");
}
@MenuItem("EventEditor/Save", true)
static function FileSave () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Save", false, 30)
static function FileSavePerform () {
Debug.Log("Load");
}
@MenuItem("EventEditor/Save As", true)
static function FileSaveAs () {
return EditorWindow.focusedWindow == EventEditorWindow.window;
}
@MenuItem("EventEditor/Save As", false, 31)
static function FileSaveAsPerform () {
Debug.Log("Load");
}