Author Topic: "NGUI" menu inside project window  (Read 4503 times)

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
"NGUI" menu inside project window
« on: December 12, 2013, 09:17:54 AM »
Hey there!

I find the "NGUI" menu in the project window useful, though I think it would be better if it were positioned lower down (for example, between "Delete" and "Import New Asset...").

I am so used to right-clicking and heading straight for the regular Unity "Create" menu. This isn't a major issue, but it would be nice if NGUI didn't mess with the position of "Create" :P

As always, keep up the great work!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "NGUI" menu inside project window
« Reply #1 on: December 12, 2013, 10:57:08 AM »
Unfortunately as far as I understand it Unity doesn't offer enough control to make this possible. It's possible to set the order of the final sub-menu, but I see no way of specifying the priority order of the root menu.

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: "NGUI" menu inside project window
« Reply #2 on: December 12, 2013, 01:24:35 PM »
The ordering within the root menu is taken from the first item in your sub-menu. So for example, the following:
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. public static class TestMenu {
  5.  
  6.         [MenuItem("Assets/NGUI2/A", false, 30)]
  7.         static void A() {
  8.         }
  9.        
  10.         [MenuItem("Assets/NGUI2/B", false, 300)]
  11.         static void B() {
  12.         }
  13.        
  14.         [MenuItem("Assets/NGUI2/C", false, 300)]
  15.         static void C() {
  16.         }
  17.  
  18. }
  19.  
will produce the following:
http://pasteboard.co/1WZBK4hg.png

But, with that said, Unity hasn't left any gaps within their numbering scheme. I personally work with increments of 100 with my menus so that they are easier to extend by other developers.

The nearest I could get to where I suggested was with priorities ranging between 20 and 29. But these do not seem ideal. Perhaps this will help anyhow :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "NGUI" menu inside project window
« Reply #3 on: December 12, 2013, 01:44:31 PM »
Hmm... So how does it work exactly? Which number controls what? What controls the order in the "Assets" menu, and what controls the order in the "Assets/NGUI2"?

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: "NGUI" menu inside project window
« Reply #4 on: December 12, 2013, 01:51:34 PM »
In the case of this example, 30 is the position of "NGUI2" within "Assets", but it also represents the very first item in the "NGUI2" submenu. For example:
  1.     [MenuItem("Assets/NGUI2/A", false, 30)]
  2.     static void A() {
  3.     }
  4.    
  5.     [MenuItem("Assets/NGUI2/B", false, 300)]
  6.     static void B() {
  7.     }
  8.    
  9.     [MenuItem("Assets/NGUI2/C", false, 31)]
  10.     static void C() {
  11.     }
  12.    
  13.     [MenuItem("Assets/NGUI2/D", false, 30)]
  14.     static void D() {
  15.     }
  16.  
will produce:
  1. - Select Dependencies(30)
  2. - NGUI2(30)
  3.     - A(30)
  4.     - D(30)
  5.     - C(31)
  6.     ----------
  7.     - B(300)
  8. --------------------
  9. - Refresh(40)
  10.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "NGUI" menu inside project window
« Reply #5 on: December 12, 2013, 02:32:47 PM »
Hmm.. interesting. How did you figure this out? And the separator -- I assume it occurs after....?

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: "NGUI" menu inside project window
« Reply #6 on: December 12, 2013, 03:55:11 PM »
Quote
How did you figure this out?
After a LOT of trial and error and a question to Shawn White ;)

My asset makes heavy use of menu items and their ordering so I felt that this was important to figure out.

Quote
And the separator -- I assume it occurs after....?
The separator will appear above items which are set apart by increments of 30, though in my opinion increments of 100 is neater and easier to maintain.
  1. // Separators at increments of 30
  2. [MenuItem("Test/ABC/1", false, 10)]
  3. static void ABC_1() {
  4. }
  5. [MenuItem("Test/ABC/2", false, 10)]
  6. static void ABC_2() {
  7. }
  8. [MenuItem("Test/ABC/3", false, 10)]
  9. static void ABC_3() {
  10. }
  11. [MenuItem("Test/ABC/4", false, 10)]
  12. static void ABC_4() {
  13. }
  14. [MenuItem("Test/ABC/5", false, 30)]
  15. static void ABC_5() {
  16. }
  17. [MenuItem("Test/ABC/6", false, 60)]
  18. static void ABC_6() {
  19. }
  20.  
  21. // Separators at increments of 100
  22. [MenuItem("Test/DEF/1", false, 100)]
  23. static void DEF_1() {
  24. }
  25. [MenuItem("Test/DEF/2", false, 200)]
  26. static void DEF_2() {
  27. }
  28.                
  29. [MenuItem("Test/GHI/1", false, 200)]
  30. static void GHI_1() {
  31. }
  32. [MenuItem("Test/GHI/2", false, 300)]
  33. static void GHI_2() {
  34. }
  35.  

Screen shots of above menu:
http://pbrd.co/JbTqlG
http://pbrd.co/JbTuBT
http://pbrd.co/JbTx0z

I hope that this helps, but please let me know if you have further questions and I will do my best to help :)

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: "NGUI" menu inside project window
« Reply #7 on: December 12, 2013, 03:58:08 PM »
Btw, a note about the separator which appears below the "Assets/Create" submenu. This one seems to break the rule and so perhaps is inserted explicitly by the Unity menu generation code. i.e. doesn't use the 'MenuItem" attribute. That is purely a guess.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: "NGUI" menu inside project window
« Reply #8 on: December 12, 2013, 07:31:56 PM »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "NGUI" menu inside project window
« Reply #9 on: December 13, 2013, 05:37:14 AM »
Interesting... thanks for the tips!

kreso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: "NGUI" menu inside project window
« Reply #10 on: May 05, 2014, 06:48:55 PM »
Just updated my NGUI, and it 'overtook' my context menu in project window yet again.
I don't really understand why the menu item is needed there, but would appreciate at least if it would be moved to the bottom (it looks like you have enough information now, and other plugins use bottom of menu, so it is possible).

I'm off now, spending 30 minutes again on removing it from the menu...since I forgot how I removed it last time..

Thanks for considering to removing it completely, or at least to bottom of context-menu.

Kreso

EDIT: Actually another though. You could move the 2 'Create' commands into 'Create' subgroup (like tk2d does), and other 2 ('open' atlas..) just move them to main menu (they don't belong there anyway).
Thanks.