- Home /
How would I add OS X menu bar functions to a Unity app?
Is it possible to add menu items to the OSX menu bar (file, edit, view, etc) from a plugin within Unity, and if so, where would one look (in terms of documentation or example code) to start on such a project?
Obviously, ideally, these menu items would also have some sort of callback to a function within Unity.
Answer by jonas-echterhoff · Nov 18, 2009 at 01:13 PM
I think it should be possible to add menus in OS X from an Objective-C plugin. The code should look something like this:
// Add the submenu
newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Flashy" action:NULL keyEquivalent:@""];
newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Flashy"];
[newItem setSubmenu:newMenu];
[newMenu release];
[[NSApp mainMenu] addItem:newItem];
[newItem release];
It probably takes some experimenting to get it right, and we may change the menu implementation in some future builds, but I'm sure it is possible right now.
This would of course only work in standalones, we don't support C plugins in the web player.
Well, I had to learn the basics of Objective-C first, but I got this to work, as well as system level alerts to work! Now just the callbacks and I'm ready for some basic app development using Unity!
I implemented a basic polling method to check to see if anything has changed on the Cocoa side, since passing a delegate seems impossible. Done.
Answer by Aras · Nov 18, 2009 at 07:02 AM
If you want to add menu items to a standalone game: that's easily not possible (right now at least). It should be possible with some hacks or good knowledge of the OS (see Jonas' answer for OS X case).
If you want to add menu items to Unity editor: use @MenuItem attribute in your script, and write small "bridge" code so that they call into your plugin.
It seems $$anonymous$$is correct, although it does require some knowledge of Objective-C, which I didn't have. I haven't gotten the callbacks working yet, but that should only be a matter of time.
I look forward to when this feature is included in a simple way inside Unity!
Answer by Brian-Kehrer · Nov 21, 2009 at 05:19 PM
It also appears you can modify the interface builder files directly by right clicking on the built Unity game, and selecting show package contents.
Contents->Resources->MainMenu.nib
However, I'm not sure if it's possible to poll these actions from within Unity, or at least not in as efficient a way. If there were such a method, it would be ideal.
However, if there are purely Cocoa interface elements to be added that don't need to interact with Unity (such as an about window), this can be done.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162900im_/https://answers.unity.com/themes/thub/images/avi.jpg)