• 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
11
Question by Grady · Jan 04, 2012 at 07:35 AM · inspectormenudropdown

How to create a drop down menu in editor inspector

Hey everyone,

Now I know there have been quite a few questions like t$$anonymous$$s, but just hear me out!!!!!

Want I want to do, is just have a drop down menu that the user can click on, and then select a value in the inspector where the rest of the variables are.... I don't want it in any extra GUI Window or anyt$$anonymous$$ng, just next to the rest of the variables for a script in the editor!!!!!!! Here is a link to an image on my website that I snapshotted from unity that basically shows what I'm looking for!!!!!!!!!!!!!!!

Where you see "Dropdown" in my lovely computer hand writing, that is the variable name like the rest of them. When the user clicks on "Var value" I want it to show a dropdown box in w$$anonymous$$ch they can then pick from a list of values to assign to the variable. And the other little scribble next to that is where there would be a little arrow most likely to show that it's a drop down menu!!!!!!

It's sort of like a Editor GUI Popup, except I want it in the inspector window next to the rest of the variables!

Any suggestions are welcome!!!!!!!!!!!

Thanks!

-Grady

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

5 Replies

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

Answer by VivienS · Jan 04, 2012 at 09:56 AM

Hi Grady.

I t$$anonymous$$nk what you want is a custom enumeration and a public variable of the type of t$$anonymous$$s enumeration. Unity should display it as a drop down menu, with the elements of the enum as list items. Try:

 enum myEnum // your custom enumeration
 {
    Item1, 
    Item2, 
    Item3
 };

 var dropDown = myEnum.Item1;  // t$$anonymous$$s public var should appear as a drop down

cheers, Vivien

Comment
Add comment · Show 7 · 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 Grady · Jan 04, 2012 at 11:45 AM 0
Share
avatar image Grady · Jan 04, 2012 at 11:48 AM 0
Share
avatar image VivienS · Jan 04, 2012 at 02:47 PM 0
Share
avatar image Hathakas · Feb 04, 2015 at 09:58 PM 0
Share
avatar image SkyGolem · Nov 11, 2018 at 03:30 PM 0
Share
avatar image simulism SkyGolem · Dec 29, 2021 at 09:32 PM 1
Share
Show more comments
avatar image
41

Answer by NazmunAnny · Dec 29, 2014 at 05:33 PM

T$$anonymous$$s would be the c# version of the code

public enum Orientation{ Left, Right, Top, Bottom }

public Orientation orientation;

alt text


screen shot 2014-12-29 at 11.28.40 pm.png (9.7 kB)
Comment
Add comment · Show 4 · 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 Zymurer · Sep 27, 2018 at 02:22 PM 2
Share
avatar image Michael_Berna · Dec 22, 2019 at 03:10 AM 0
Share
avatar image Gawron10001 Michael_Berna · Jan 05, 2020 at 03:28 PM 0
Share
avatar image Michael_Berna Gawron10001 · Jan 05, 2020 at 07:56 PM 0
Share
avatar image
4

Answer by hackerG7 · Oct 21, 2020 at 10:22 AM

You can try the asset dropdown attribute, it is simple and allows dynamic list or array to be selected but not only enum. https://assetstore.unity.com/packages/tools/utilities/dropdown-attribute-180951

Example:

 public class Player : Monobehaviour{
     public List<string> NameList; 
     
     [Dropdown("NameList")]//input the path of the list
     public string MyName;
 }

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
3

Answer by triangle4studios · Oct 21, 2020 at 05:53 AM

Enums are declared the same way you declare a class or a struct.

Here is a more complete answer for those who came here looking for an answer and not part of one.

     using UnityEngine;
     public class UpgradeModule : MonoBehaviour
     {
         public MyEnum myDropDown = new MyEnum();
     }
     
     public enum MyEnum
     {
         Item1, 
         Item2, 
         Item3
     };

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 triangle4studios · Oct 21, 2020 at 05:54 AM 0
Share
avatar image benbastien · Feb 11, 2021 at 09:42 PM 0
Share
avatar image simulism benbastien · Dec 29, 2021 at 09:33 PM 0
Share
avatar image
0

Answer by HariharanVN5 · Mar 05, 2021 at 06:20 AM

Actually If you planning not to expose the enum varialbles , we can do with Serializefields

 enum Directions
 {up,down,left,right}
 
 #pragma warning disable 0649

 [Serializefield] Directions direction;

 #pragma warning disable 0649

t$$anonymous$$s will expose the enums , I added serializefield to avoid warnings

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Inspector scripting, adding lists, checkboxes and buttons [With Image] 0 Answers

How can I make a small context menu in the inspector? 3 Answers

Making a collapsible menu in the inspector 4 Answers

to point a selfwritten class in the inspector (drag n drop) 0 Answers

Updating Tab Menu 2 Answers


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