Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 FedericoDeBona · Jun 28, 2019 at 08:20 PM · editoreditor-scriptingmaterialseditorguieditor extension

How can i create a pup-up menu like the one for choose the shader on materials in unity 2019?

Hi guys, I'm working on an ediotr tool, and I need to create the pop-up menu like the one in the material inspector. Look the image to understand what I mean: https://ibb.co/fFHVvd8 I searched a lot on Internet, but i couldn't find nothing. I also tried to check the Unity source code on GitHub, but nothing. I hope you can help me.

Thank you in advance!

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

1 Reply

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

Answer by nratcliff · Jun 29, 2019 at 12:55 AM

It took some digging, but I found the shader dropdown implementation in the source reference here. Using that, I put together a quick custom editor that has its own AdvancedDropdown as an example: Custom Dropdown Expanded
Custom Dropdown Filter
Custom Dropdown Selected

 using System;
 using UnityEditor;
 using UnityEditor.IMGUI.Controls;
 using UnityEngine;
 
 [CustomEditor(typeof(ScriptWithDropdown))]
 public class EditorWithDropdown : Editor
 {
     private string selectedItemName = null; // the currently selected item
     private AdvancedDropdownState dropdownState = null; // the stored state of the dropdown
 
     public override void OnInspectorGUI()
     {
         Rect position = EditorGUILayout.GetControlRect();
 
         // set the dropdown label
         var label = new GUIContent("Custom Dropdown");
         if(selectedItemName != null)
         {
             label = new GUIContent(selectedItemName);
         }
 
         // draw the dropdown
         if(EditorGUI.DropdownButton(position, label, FocusType.Keyboard))
         {
             var dropdown = new CustomAdvancedDropdown(
                 dropdownState, Dropdown_ItemSelected);
             dropdown.Show(position);
         }
 
         base.OnInspectorGUI();
     }

     // called from CustomAdvancedDropdown when selection changes
     private void Dropdown_ItemSelected(string item)
     {
         selectedItemName = item;
     }
 
     private class CustomAdvancedDropdown : AdvancedDropdown
     {
         private Action<string> onItemSelected;
 
         public CustomAdvancedDropdown(AdvancedDropdownState state, Action<string> onItemSelected)
             : base(state)
         {
             minimumSize = new Vector2(270, 308);
             this.onItemSelected = onItemSelected; // add item selected callback
         }
 
         // builds the dropdown menu
         protected override AdvancedDropdownItem BuildRoot()
         {
             // create the root element
             AdvancedDropdownItem root = new AdvancedDropdownItem("Root Name");
 
             // add basic child elements
             root.AddChild(new AdvancedDropdownItem("Item 1"));
             root.AddChild(new AdvancedDropdownItem("Item 2"));
             root.AddChild(new AdvancedDropdownItem("Item 3"));
             root.AddChild(new AdvancedDropdownItem("Item 4"));
             root.AddChild(new AdvancedDropdownItem("Item 5"));
             root.AddChild(new AdvancedDropdownItem("etc."));
 
             return root;
         }
 
         // called when an item is selected
         protected override void ItemSelected(AdvancedDropdownItem item)
         {
             // alert item selected
             onItemSelected(item.name);
         }
     }
 }

Hopefully this helps! I can't seem to find any documentation for AdvancedDropdown, but both of the source reference links I provided above give quite a bit of insight.

Good luck!

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 FedericoDeBona · Jun 29, 2019 at 05:02 AM 0
Share

Thank you so much!

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

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

SceneView.onSceneGUIDelegate GUI sorting problem 1 Answer

Better Unity Event UI 0 Answers

How to access empty Material slots on a ModelImporter via script? 1 Answer

Custom inspector difficulties creating a Box / Group like widget 1 Answer

Custom Inspector for a List ? 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