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
1
Question by ruben_hiet · Dec 12, 2012 at 01:32 PM · editormenuitemcheckboxmenu-itemradio

Menu Items as checkboxes/radio buttons

Hello everyone,

I am making some menu items to enable some functions but comming across a problem. if you go to unity3d and click on the edit menu item (default in the editor) and then all the way down to graphics emulation or network emulation you see some new buttons in a menu next to it with a checkbox. when you select 1 the others are disabled.

i want to make the same function in my menu item but now my question is how? I searched on google for a while now and haven't find anything close to it.

tried to just add true/false at the end of the name but of course that isn't possible either... so how can i make such radio/checkboxes buttons in my menu items?

Thx in advance,

Ruben

Comment
Add comment · Show 7
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 Landern · Dec 12, 2012 at 01:33 PM 0
Share

Are you talking about in a Scene(OnGUI) or are you making an editor extension and want that behavior in the editor?

avatar image ruben_hiet · Dec 12, 2012 at 01:37 PM 0
Share

in the editor like this : [$$anonymous$$enuItem ("Objecthandler/Default option/Objects")] but then Objects must be a boolean with [$$anonymous$$enuItem ("Objecthandler/Default option/Textures")] .

it has to change a boolean in editor script turn true/false

avatar image ruben_hiet · Dec 14, 2012 at 12:21 PM 0
Share

nobody knows something about this? :(

avatar image MOrlando616 · Apr 06, 2013 at 04:49 PM 1
Share

I'm not sure why everyone seems confused by the question. He wants his menu item to support having a checkmark next to it so the user can visually see the state of the boolean he's toggling behind the scenes within the editor.

Having said that, I don't know how to do it...if you find out, post your own answer. :)

avatar image AlucardJay · Apr 06, 2013 at 06:47 PM 1
Share

I really don't think you can create a menu item with sub-directories and then pick one of them like you are asking. The closest thing I could find in the Scripting Reference is this : http://docs.unity3d.com/Documentation/ScriptReference/Generic$$anonymous$$enu.html

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by darkbaram · Mar 07, 2016 at 03:27 PM

This has solution. Unity support function - Menu.SetChecked(). You can implement toggle menuitem using this function.

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
avatar image
1

Answer by Selmar · Mar 15, 2016 at 08:50 PM

As @darkbaram said, Menu.SetChecked(). From http://answers.unity3d.com/answers/1146949/view.html :

  using UnityEditor;
  [InitializeOnLoad]
  public static class CheckmarkMenuItem {
  
      private const string MENU_NAME = "Example/Toggle";
  
      private static bool enabled_;
      /// Called on load thanks to the InitializeOnLoad attribute
      static CheckmarkMenuItem() {
          CheckmarkMenuItem.enabled_ = EditorPrefs.GetBool(CheckmarkMenuItem.MENU_NAME, false);
  
          /// Delaying until first editor tick so that the menu
          /// will be populated before setting check state, and
          /// re-apply correct action
          EditorApplication.delayCall += () => {
              PerformAction(CheckmarkMenuItem.enabled_);
          };
      }
  
      [MenuItem(CheckmarkMenuItem.MENU_NAME)]
      private static void ToggleAction() {
  
          /// Toggling action
          PerformAction( !CheckmarkMenuItem.enabled_);
      }
  
      public static void PerformAction(bool enabled) {
  
          /// Set checkmark on menu item
          Menu.SetChecked(CheckmarkMenuItem.MENU_NAME, enabled);
          /// Saving editor state
          EditorPrefs.SetBool(CheckmarkMenuItem.MENU_NAME, enabled);
  
          CheckmarkMenuItem.enabled_ = enabled;
  
          /// Perform your logic here...
      }
  }
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
avatar image
0

Answer by Loius · Apr 06, 2013 at 05:23 PM

Well, a silly brute force way would be to write a script that edits and recompiles your scripts whenever you want a state change, and use altcode checkmarks in the menu names.

But that's silly.

I don't see a way in the scripting reference, and I don't recall seeing any screenshots of that behaviour in non-Unity menus, sorry.

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
0

Answer by rzo · Jul 20, 2015 at 12:45 PM

Sadly, this is the only solution I was able to come up with. But it may be useful for others.

 [MenuItem("Assets/Bundle Builder/Force Offline/On")]
 public static void ForceOfflineTrue()
 {
     AssetManager.Instance.ForceOffline = true;
 }

 [MenuItem("Assets/Bundle Builder/Force Offline/Off")]
 public static void ForceOfflineFalse()
 {
     AssetManager.Instance.ForceOffline = false;
 }

 [MenuItem("Assets/Bundle Builder/Force Offline/On", true)]
 public static bool CanForceOfflineTrue()
 {
     return AssetManager.Instance.ForceOffline == false;
 }

 [MenuItem("Assets/Bundle Builder/Force Offline/Off", true)]
 public static bool CanForceOfflineFalse()
 {
     return AssetManager.Instance.ForceOffline == true;
 }


It creates Submenu in Asset/BundleBuilder/Force Offline with two items On and Off (The first two methods gets called when appropriate item is clicked). To indicate the state of the Force Offline item, I've added other two methods (validation functions), that let enabled only the item that changes the state—i.e. when Force Offline is set to true, only Off item will be enabled.

This soultion is far from being optimal, but it works somehow for my case.

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

(Editor) How to add Checkmarks to MenuItems 4 Answers

MenuItem toggle getting reset on play. 0 Answers

Editor Scripting Question 1 Answer

Can I create MenuItem from code? 3 Answers

Unity 2017.1.0p5: Editor: Cannot add menu item 'GameObject/UI/Text' for method 'MenuOptions.AddText' because a menu item with the same name already exists. 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