Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by Long2904 · Feb 28, 2020 at 01:26 PM · inspectorenumcustom-inspectoreditorguilayoutshowing

What is the efficient way of showing variables depend on enum in custom inspector?

I want the inspector to show different variable depends on the enum you choose. I know i need to use custom inspector but there are some general variables i want to show that don't depend on the enum and always showing. How can i achieve it and what the general and efficient way of showing custom variable?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Kishotta · Feb 28, 2020 at 08:43 PM

You can do this with some conditional control flow in a custom inspector:

 public enum Group { One, Two }
 
 public class Client : MonoBehaviour {
     public Group Group;
     public bool GroupOneData;
     public float GroupTwoData;
     public string IndependentData;
 }
 
 [CustomEditor (typeof (Client))]
 public class ClientEditor : Editor {
     void OnInspectorGUI () {
         Client client = (Client)target;
         
         // Display dropdown
         client.Group = (Group)EditorGUILayout.EnumPopup ("Group", client.Group);

         // Display conditional for one    
         if (client.Group == Group.One) {
             client.GroupOneData = EditorGUILayout.Toggle ("Bool", client.GroupOneData);
         }

         // Display conditional for two
         if (client.Group == Group.Two) {
             client.GroupTwoData = EditorGUILayout.FloatField("Float", client.GroupTwoData);
         }

         // Display always
         client.IndependentData = EditorGUILayout.TextField ("String", client.IndependentData);
     }
 }

When One is selected for Group, the "Bool" toggle will appear. When Two is selected for Group, the "Float" field will appear. The "String" text field will appear regardless of which option is selected. If, in the future, you add an additional Three option to the group enum, neight the "Bool" nor "Float" fields will appear if it is selected. "String" will appear no matter what.

Comment
Add comment · Show 2 · 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 Long2904 · Mar 01, 2020 at 12:58 PM 0
Share

what is the difference between editorguilayout and guilayout? Also what are the method for other data types like gameobject, int, transform, my custom script?

avatar image Raes93 · Nov 13, 2020 at 02:10 PM 0
Share

Hi, there's something not working in this script. I've created a Script with all the code shown above, but it seems not considering the Client CustomEditor Class: is this code working for anyone else?

avatar image
0

Answer by Zentiu · Feb 28, 2020 at 05:21 PM

When you have an enum with some variables in it, for your class use :

public enum bla {blie, yay, boo};

public class blu : MonoBehaviour

{

}

Comment
Add comment · Show 2 · 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 Zentiu · Feb 28, 2020 at 05:23 PM 0
Share

Something fucked up...

again..

 public enum bla {blie, yay, boo};
 public class blu : $$anonymous$$onoBehaviour
 {
     public bla enumValue;
 
 } 


This should be able to show the enum in the inspector basicly.

avatar image Long2904 Zentiu · Mar 01, 2020 at 01:01 PM 0
Share

No, i want to show different variables depend on the enum you choose. Also can u answer my question from the answer above.

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

132 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 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 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 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 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 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

Inspector - Show/hide property within custom class using enum 1 Answer

drawdefaultinspector except of one variable?? 2 Answers

Creating enum using a string array 3 Answers

Custom Inspector: Iteration/property comparison always false 0 Answers

Automatically create enum based on class children types? (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