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
0
Question by Nerethar · Jun 23, 2014 at 11:16 AM · c#guieditormodding

Add Dropdown Menues and Checkboxes to custom Editor windows

Hi folks,

I got a little problem with the editor modding, because the Unity GUI appears to have no sort of drop down menues or checkboxes implemented by default.

Let me first descripe to you what I'm about to do:

I got an array AR of a specific size in a static script A. I got an Editor Modification Script B.

In this Editorscript B I would like to choose between ONE entry of the array AR. Since only one could be active at a time a drop down menue or checkbox would make perfect sence.

I looked for some dropdown menue scripts but that mostly led to problems like "no buttons underneath the dropdown entries" or "the number of entries has to be fixed" etc. Ofc the size of the array AR is allways known, but someone who has mo idea of coding should be able to add simply entries to that array AR.

 (its initialized in a way like that:
 ... {new myClass("stuff", 1), ("morestuff", 2), ... }
 )

Someone who has no idea of coding could still edit the this list.

From this Array I would like to generate the entries in the dropdown menue. So its kinda dynamically.

I tried to work arround this by implementing a own approch of a combobox, but this seems to be a kinda unperformant way:

pseudo code:

 for( number of entries in AR )
    if( Toggle(...) )
       for(number of entries)
          uncheck Toggle
       check clicked Toggle

This obviously ends with a lot of GUI-Calls, and while this isn't that much of a bad thing since my PC can handle this I'm pretty sure there is a better way to do so.

Has anyone of you encountered similar problems or know a better way to solve this problem?

Thanks for any help.

Comment
Add comment · Show 2
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 Erisat · Jun 23, 2014 at 11:36 AM 1
Share

I'm not how the editor gui differs, but I've read that it uses the same or similar functionality as the in-game gui's. maybe this would be of some help? http://wiki.unity3d.com/index.php?title=PopupList

avatar image Nerethar · Jun 23, 2014 at 12:16 PM 0
Share

As far as i know the difference seems to be that you use guilayout ins$$anonymous$$d of gui and you don't need to add the position values. Thank you for the link. I think thats a pretty complex approach, but it seems to be an usefull one.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Munnin · May 24, 2021 at 12:30 AM

I realize this is years late, but hope it may help others down the road. You can add a dropdown menu to the Unity Inspector quite easily by doing the following.

One script, placed on the gameObject will contain the dropdown menu contents (Bool appears at top of Inspector, no matter where you place it in code) You can add a lot more to this script to really flesh out your Inspector.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CustomUnit : MonoBehaviour
 {
     
     public bool unitCrippled = false;
 
     [HideInInspector]
     public int racearrayIdx = 0;
     [HideInInspector]
     public string[] RaceArray = new string[] { "Human", "Elf", "Orc", "Goblin" };
 
     [HideInInspector]
     public int classarrayIdx = 0;
     [HideInInspector]
     public string[] ClassArray = new string[] { "Warrior", "Archer", "Mage", "etc" };
 }

The second script will add the menus to the editor itself: (This is not attached to anything) (Idx is Index. ie. slot 1, slot 2, slot 3, etc.)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(CustomUnit))]
 public class UnitEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         base.OnInspectorGUI();
 
         CustomUnit script = (CustomUnit)target;
 
         GUIContent raceArrayLabel = new GUIContent("Race");
         script.racearrayIdx = EditorGUILayout.Popup(raceArrayLabel, script.racearrayIdx, script.RaceArray);
 
         GUIContent classArrayLabel = new GUIContent("Class");
         script.classarrayIdx = EditorGUILayout.Popup(classArrayLabel, script.classarrayIdx, script.ClassArray);
 }
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

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

Unity Editor script arrows to display a variable 2 Answers

What does the code behind BeginHorizontal() and EndHorizontal() look like or is presumed to look like ? 1 Answer

Texture2D not showing in build, but shows up in editor 1 Answer

How do I get (return) all the GUI inside(contained in) a GUI rect ? 2 Answers

Distribute terrain in zones 3 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