- Home /
GUIUtility.DisplayCustomMenu().. how can I disable one of these menu items..
For some reason I cannot find any documentation on this function, I am just curious how I can disable one of the menu items. I've seen only one example, where I guess in earlier Unity versions GUIContent had an "enabled" feature, which was used then to disable a menu item, however now GUI controls are enabled/disabled using GUI.enable, so what am I suppose to do here?
Answer by Daniel-Brauer · Aug 24, 2010 at 08:19 PM
Displaying custom menu items is most easily done with the MenuItem attribute:
http://unity3d.com/support/documentation/ScriptReference/MenuItem.html
As the examples show, you can use a second function to define when the item is enabled or not.
um, no.. I'm fully aware on how to use the $$anonymous$$enuItem attribute, this is not for $$anonymous$$enuItems, or the CONTEXT context menus.. this is for the GUIUtility.DisplayCustom$$anonymous$$enu() method, which you may locate if you tried calling that in your code, as you may or may not see, it creates menu items through a GUIContent array, not through attributes.. thanks though!
I actually misread your question, because I've never heard of GUIUtility.DisplayCustom$$anonymous$$enu() and thought you made it up. Where did you find it? I don't see it in the documentation or in the UnityEngine.dll for Unity 2.6 or 3.0
it doesn't exist in the documentation, not sure why.. I found a lot of things arnt, such as the Handles class..
Answer by Daniel-Brauer · Aug 26, 2010 at 08:09 PM
Ok, I found it. It's not part of GUIUtility, but EditorUtility. There are three versions of the function:
internal static void DisplayCustomMenu(Rect position, string[] selected, SelectMenuItemFunction callback, object userData)
public static void DisplayCustomMenu(Rect position, GUIContent[] options, int selected, SelectMenuItemFunction callback, object userData)
internal static void DisplayCustomMenu(Rect position, string[] options, bool[] enabled, int[] selected, SelectMenuItemFunction callback, object userData)
As you can see, the only version with an enabled array is the third one, and it's marked internal.
The second function calls the first, which explicitly sets all the items to enabled.
I'm guessing that all three of these functions are supposed to be internal (or perhaps all public). You should file a bug report.
Answer by MattRix · May 01, 2016 at 03:42 AM
I know this question is super old, but it still comes up in searches so I might as well answer it.
I don't know why EditorUtility.DisplayCustomMenu isn't documented, but the better way to do what you want is by using GenericMenu. With GenericMenu it's easy to create menus that have dividers, disabled items, arbitrary hierarchies, etc.
Your answer
Follow this Question
Related Questions
turn .cs file on and off with keypress???? 1 Answer
Displaying Z Rotation through script 1 Answer
Displaying percentage on GUI 1 Answer
Saving selections across multiple menus? 1 Answer
Custom Material Editor 1 Answer