Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Is the "Add Component" menu available via editor scripting?

Discussion in 'Editor & General Support' started by Peter77, Dec 15, 2020.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,447
    Is there a built-in control that the "Add Component" menu uses as shown in the image below?

    I need the same functionality, I just want fill it with different items and run my own code when an item is clicked.

    upload_2020-12-15_15-47-18.png
     
  2. josh_dreemar

    josh_dreemar

    Joined:
    Jan 9, 2019
    Posts:
    8
    I know it's been a few months now, but if you or anyone else is looking for it you'll want to use an AdvancedDropdown: https://docs.unity3d.com/ScriptReference/IMGUI.Controls.AdvancedDropdown.html

    If you want to run code when an item is clicked, you just need to override the ItemSelected method.

    (Edit)
    I just want to point out that the ItemSelected method will only be fired once an AdvancedDropdownItem without any children is selected.
     
    Last edited: May 5, 2021
    Rallix and Peter77 like this.