Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 $$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!

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

iOS location permission plugin build fails 0 Answers

xCode to Unity communication? 1 Answer

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges