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.

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.

It also appears you can modify the interface builder files directly by right clicking on the built Unity game, and selecting show package contents.


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.

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.