• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Brian-Kehrer · Nov 18, 2009 at 05:14 AM · guipluginxcodeobjective-c

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brian-Kehrer · Nov 18, 2009 at 05:12 PM 0
Share

Thanks, I'll give this a spin sometime this week!

avatar image Brian-Kehrer · Nov 21, 2009 at 02:37 AM 0
Share

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!

avatar image Brian-Kehrer · Nov 21, 2009 at 05:42 AM 0
Share

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.

avatar image
2

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brian-Kehrer · Nov 21, 2009 at 03:11 AM 0
Share

It seems Jonas 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!

avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Call Unity class in XCode 1 Answer

Using NavigationController in an iOS plugin 1 Answer

Can you build iOS plugins using objective-c or only with pure c? 1 Answer

iOS location permission plugin build fails 0 Answers

xCode to Unity communication? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges