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 /
  • Help Room /
avatar image
0
Question by d112570 · Apr 19, 2014 at 06:34 PM · custom-inspectorenumpopup

Help with my enumpopup.

Got this code in my normal script

 public class Info : MonoBehaviour {
 public enum Category {Asteroid, Galaxy, Planet, Satellite, Star} // My list.
 public Category category;} // This creates my Popup in my normal inspector.

In my custom inspector I have this.

 Info myTarget = (Info)target;
 myTarget.Category = (int)(MyEnumType)EditorGUILayout.EnumPopup("Category:", (MyEnumType)Enum.GetValues(typeof(MyEnumType)).GetValue(myTarget.Category));

I tried to convert someones answer to mine, what goes into MyEnumType, for me its just an enum, what about (int) is that for the index or should it be something else? I believe the rest I have correct.

Can someone please help me fix this.

Comment
Add comment · Show 1
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 d112570 · Apr 19, 2014 at 06:41 PM 0
Share

P.S. when I code check, I get an error saying $$anonymous$$yEnumType could not be found. I am so lost on this one, do you have to declare $$anonymous$$yEnumType?

1 Reply

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

Answer by d112570 · Apr 21, 2014 at 11:15 AM

 myTarget.category = (Category)EditorGUILayout.EnumPopup("Category",myTarget.category);

If someone explained it correctly I would of not have to search the web for 4 days, it was quite annoying. But this code worked that I finally translated. No site seemed to have had an answer, and none worked for me. Here I show how it should be.

First part is this (Info Script). Move the enum before class

 public enum Category {Asteroid,Galaxy,Planet,Satellite,Star}
 public class Info : MonoBehaviour {
 public Category category;} // This creates my Popup in my normal inspector.

Second part is this. (Custom Editor Script)

 using UnityEditor;
     
     [CustomEditor(typeof(Info))]
     public class InfoEditor : Editor    
 {
     public override void OnInspectorGUI()
     {
         Info myTarget = (Info)target;
         myTarget.category = (Category)EditorGUILayout.EnumPopup("Category",myTarget.category);
         
     }}

Easy as that, I seen answers that did't work with tons of more code and it didn't work. :-( Maybe not compatible with Unity 4.3.

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 d112570 · Apr 21, 2014 at 11:21 AM 0
Share

For the newbies, the Editor script goes in the Project/Editor folder and drag the class script onto the relevant gameObject. The inpector will be overwritten from the class script and will use the editor script ins$$anonymous$$d. But if you want to see the class script as a test or something, add this code somewhere after onInspectorGUI();

 base.OnInspectorGUI();
avatar image SuperBase · Aug 19, 2016 at 10:18 PM 0
Share

This worked like a charm for me. Thank you very much!

avatar image Dysseus · Sep 13, 2016 at 06:27 PM 0
Share

You are a Hero!

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

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

Related Questions

Switch between HorizontalLayoutGroup and VerticalLayoutGroup using Custom Inspector Editor [UI] [Custom Editor] 0 Answers

How do you conditionally hide some enum values in custom inspector? 0 Answers

Custom Editor on Serialized Objects which are not derived from Monobehaviour 1 Answer

OnPreviewGUI for Canvas and UI Elements 0 Answers

Custom Editor from a Non-Monobehavior Script 0 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