{"id":16210882,"url":"https://github.com/solidalloy/unitydropdown","last_synced_at":"2025-03-19T09:30:34.830Z","repository":{"id":48029057,"uuid":"450945669","full_name":"SolidAlloy/UnityDropdown","owner":"SolidAlloy","description":"A better dropdown window for Unity Editor","archived":false,"fork":false,"pushed_at":"2023-11-02T18:14:44.000Z","size":2451,"stargazers_count":97,"open_issues_count":2,"forks_count":22,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-28T17:25:20.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SolidAlloy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-22T21:59:43.000Z","updated_at":"2025-02-19T06:50:37.000Z","dependencies_parsed_at":"2024-10-27T20:27:55.781Z","dependency_job_id":"0e7b6140-9680-4478-a356-d6fab57362f6","html_url":"https://github.com/SolidAlloy/UnityDropdown","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidAlloy%2FUnityDropdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidAlloy%2FUnityDropdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidAlloy%2FUnityDropdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidAlloy%2FUnityDropdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SolidAlloy","download_url":"https://codeload.github.com/SolidAlloy/UnityDropdown/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243980258,"owners_count":20378368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T10:44:46.961Z","updated_at":"2025-03-19T09:30:34.824Z","avatar_url":"https://github.com/SolidAlloy.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity Dropdown\nA better-looking dropdown window for Unity Editor that can easily replace GenericMenu in your editor tools.\n\n[![openupm](https://img.shields.io/npm/v/com.solidalloy.unity-dropdown?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.solidalloy.unity-dropdown/)\n\nUnity Dropdown is a replacement for GenericMenu with a similar functionality but better visuals and more features like search bar.\n\n![general-screenshot](/.images/general-screenshot.png)\n\n## Installation\n\n:heavy_exclamation_mark: Before installing the package, please disable the **Assembly Version Validation** option in **Player Settings**.\n\n### Install with OpenUPM\n\nOnce you have the [OpenUPM cli](https://github.com/openupm/openupm-cli#installation), run the following command:\n\n```openupm install com.solidalloy.unity-dropdown```\n\nOr if you don't have it, add the scoped registry to manifest.json with the desired dependency semantic version: \n\n```json\n  \"scopedRegistries\": [\n    {\n      \"name\": \"package.openupm.com\",\n      \"url\": \"https://package.openupm.com\",\n      \"scopes\": [\n        \"com.solidalloy\",\n        \"com.openupm\",\n        \"org.nuget\"\n      ]\n    }\n  ],\n  \"dependencies\": {\n    \"com.solidalloy.unity-dropdown\": \"1.1.1\"\n  },\n\n```\n\n### Install via Package Manager\n\nProject supports Unity Package Manager. To install the project as a Git package do the following:\n\n1. In Unity, open **Project Settings** -\u003e **Package Manager**.\n2. Add a new scoped registry with the following details:\n   - **Name**: package.openupm.com\n   - **URL**: https://package.openupm.com\n   - Scope(s):\n     - com.openupm\n     - com.solidalloy\n     - org.nuget\n3. Hit **Apply**.\n4. Go to **Window** -\u003e **Package Manager**.\n5. Press the **+** button, *Add package from git URL*.\n6. Enter **com.solidalloy.unity-dropdown**, press **Add**.\n\n## Example of Usage\n\n```csharp\nprivate void ShowWarriorDropdown(Type currentValue)\n{\n    var dropdownItems = new List\u003cDropdownItem\u003cType\u003e\u003e();\n\n    dropdownItems.Add(new DropdownItem\u003cType\u003e(typeof(Archer), \"Ranged/Archer\", selected: true));\n    dropdownItems.Add(new DropdownItem\u003cType\u003e(typeof(Crossbowman), \"Ranged/Crossbowman\"));\n    dropdownItems.Add(new DropdownItem\u003cType\u003e(typeof(Knight), \"Melee/Knight\"));\n    dropdownItems.Add(new DropdownItem\u003cType\u003e(typeof(Lancer), \"Melee/Lancer\"));\n    dropdownItems.Add(new DropdownItem\u003cType\u003e(typeof(Cavalryman), \"Melee/Cavalryman\"));\n    \n    dropdownItems.Find(item =\u003e item.Value == currentValue).IsSelected = true;\n\n    var dropdownMenu = new DropdownMenu\u003cType\u003e(dropdownItems, currentValue, selectedType =\u003e (Warrior)Activator.CreateInstance(selectedType));\n    \n    dropdownMenu.ShowAsContext();\n}\n\nprivate void DrawWarriorField(Rect position, Type currentType)\n{\n    if (EditorGUI.DropdownButton(position, currentType.Name, FocusType.Keyboard))\n    {\n        var warrior = ChooseWarrior(currentType);\n    }\n}\n```\n\nTo create a menu, you first need to create a collection of dropdown items. The minimum information you must provide to each item is its path and value, which can be of any type. The collection can be a list or array, it doesn't matter. Then, a dropdown menu is created by passing the collection of items to its constructor, the current value that should be selected when the dropdown is open, and an action indicating what is done to the newly selected value (e.g. assignment to a serialized property).\n\nYou can replace your `GenericMenu` with a **DropdownMenu** everywhere. For example, you can use it with `EditorGUI.DropdownButton()`. The dropdown window will look like this:\n\n![example-usage](/.images/example-usage.png)\n\n## More Info\n\n### DropdownItem\n\nOnce the number of items pass a certain threshold (10 items by default), a search bar will show up where users can filter items by their names:\n\n![searchbar](/.images/searchbar.gif)\n\nAs you can see on the previous image, the items in search appeared by their full paths. If you want to change this behavior, pass a parameter called **searchName** to `DropdownItem`:\n\n```csharp\ndropdownItems.Add(new DropdownItem\u003cType\u003e(typeof(Archer), \"Ranged/Archer\", searchName: \"Archer\"));\n```\n\n![searchName](/.images/searchName.gif)\n\nYou can also put icons for the items:\n\n```csharp\nvar transform = go.GetComponent\u003cTransform\u003e();\nvar collider = go.GetComponent\u003cCollider\u003e();\n\nvar dropdownItems = new DropdownItem\u003cComponent\u003e[]\n{\n    new DropdownItem\u003cComponent\u003e(transform, \"Transform\", icon: EditorGUIUtility.ObjectContent(transform, typeof(Transform)).image),\n    new DropdownItem\u003cComponent\u003e(collider, \"Collider\", icon: EditorGUIUtility.ObjectContent(collider, typeof(Collider)).image)\n};\n```\n\n![icon](/.images/icon.png)\n\nTo mark an item as selected, pass `selected = true` to the item's constructor:\n\n```csharp\nnew DropdownItem\u003cstring\u003e(\"Archer\", \"Ranged/Archer\", isSelected: true);\n```\n\nYou can also mark an item as selected after gathering all the needed items:\n\n```csharp\nvar itemToSelect = dropdownItems.Find(item =\u003e item.Value == currentValue);\n\nif (itemToSelect != null)\n    itemToSelect.IsSelected = true;\n```\n\nHowever, make sure to do it before passing the items to the `DropdownMenu` constructor. When `DropdownMenu` is created, it builds a node tree from the items, so it's necessary to find a node to mark it as selected:\n\n```csharp\nvar dropdownMenu = new DropdownMenu(dropdownItems, selectedItem =\u003e OnItemSelected(selectedItem));\ndropdownMenu.ShowAsContext();\n\ndropdownItems[2].IsSelected = true; // This will be of no effect\n\n// But this will work\ndropdownMenu.SelectedNode = dropdownMenu.EnumerateNodes().FirstOrDefault(node =\u003e node.Value == someValue);\n```\n\n### DropdownMenu constructor optional arguments\n\n- ***searchbarMinItemsCount*** (10 by default) - the minimum number of items at which to show the search bar. If you want to see a search bar every time, even if there are only two items in the menu, set it to 0.\n- ***sortItems*** (false by default) - whether to sort items alphabetically. It sorts items very efficiently, so if you have a large number of items, this option will be better rather than sorting the items by yourself before passing them to DropdownMenu.\n- ***showNoneElement*** (false by default) - whether to show the \"**None**\" option in the dropdown menu. This option's value always equals to null for reference types, or to the default instance of a struct. It may be useful when the field is not always supposed to be filled with some value and is allowed to be null. It behaves a little bit differently from regular items: when the list is scrolled, it always stays on top, and it's always hidden when the user searches for an item.\n\n![none](.images/none.gif)\n\n### More functionality with DropdownMenu\n\nUnlike GenericMenu, DropdownMenu exposes a lot of properties and methods so that you can expand certain folders, select nodes, delete items dynamically.\n\n`ExpandAllFolders()` expands all the folder in a dropdown. By default, only the folder where the item is selected is expanded. But you may want the user to see all the items in folders at a glance.\n\n```csharp\nvar dropdownMenu = new DropdownMenu(dropdownItems, selectedItem =\u003e OnItemSelected(selectedItem));\ndropdownMenu.ExpandAllFolders();\ndropdownMenu.ShowAsContext();\n```\n\n`DropdownMenu` builds a node tree containing of folders and items or other folders in them. Enumerate these nodes with the `EnumerateNodes()` method. Search for the folder or an item you are interested in and operate on it:\n\n```csharp\nvar meleeFolder = dropdownMenu.EnumerateNodes().FirstOrDefault(node =\u003e node.Name == \"Melee\");\nmeleeFolder.Expanded = true;\nmeleeFolder.ChildNodes.RemoveAt(1);\n```\n\n### DropdownWindow\n\n`dropdownMenu.ShowAsContext()` actually returns an instance of `DropdownWindow` that exposes all properties of `EditorWindow`. So, you can check its position, or `Close()` it before the user makes a choice:\n\n```csharp\nvar dropdownWindow = dropdownMenu.ShowAsContext();\nDebug.Log($\"position: {dropdownWindow.position}, has focus: {dropdownWindow.hasFocus}\");\ndropdownWindow.Close();\n```\n\nIn addition to `ShowAsContext()`, DropdownMenu has the `ShowDropdown()` method that takes a `Vector2` in to show the dropdown at a given posiiton. The position represents the left top corner of the dropdown. \n\nDropdownMenu calculates the window width itself based on the length of the longest item in the list, but you can supply it with a custom height. The min height is 100 pixels, and the max is 600 px. If you provide a number out of the range, it will be clamped.\n\n```csharp\ndropdownMenu.ShowAsDropdown(new Vector2(100, 300));\ndropdownMenu.ShowAsContext(windowHeight: 300);\ndropdownMenu.ShowDropdown(dropdownMenu.GetCenteredPosition()); // There's a method that will center a window properly based on its height and width.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidalloy%2Funitydropdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidalloy%2Funitydropdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidalloy%2Funitydropdown/lists"}