question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Request] Multiselect dropdown with different than enum types

See original GitHub issue

This is effectively mixing [EnumFlags] with [Dropdown] like support.

Use case:

I need to create list of strings, where each string comes from a given (not known in compile time, but known in editor - so I cannot use enum) pool and each string can only appear once.

Example:

	[MultiDropdown("GetVectorValues")]
	public List<Vector3> AllowedDirections; // I can select more than one,
                                                // but each one at most once

	private DropdownList<Vector3> GetVectorValues()
	{
		return new DropdownList<Vector3>()
		{
			{ "Right",   Vector3.right },
			{ "Left",    Vector3.left },
			{ "Up",      Vector3.up },
			{ "Down",    Vector3.down },
			{ "Forward", Vector3.forward },
			{ "Back",    Vector3.back }
		};
	}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
RunninglVlancommented, Jan 18, 2021

+1 for MultiDropdown - “make Dropdown* support collection fields” feature. I’m using code from “In the meantime, you can achieve it like this”, and added a CustomPropertyDrawer for that inner class to get rid of unnecessary Folding in the Editor, as it’s basically one field class:

[CustomPropertyDrawer(typeof(Direction))]
public class DirectionDrawer : PropertyDrawer {
    private static string Property => nameof(Direction.value);

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
        EditorGUI.PropertyField(position, property.FindPropertyRelative(Property));
    }
}
2reactions
dbrizovcommented, Mar 6, 2020

This is cool, I will implement it. In the meantime, you can achieve it like this. I haven’t tested this code, but it should work.

public List<Direction> AllowedDirections;

[Serializable]
public struct Direction
{
    [Dropdown("GetVectorValues")]
    public Vector3 Value;

    private DropdownList<Vector3> GetVectorValues()
    {
	return new DropdownList<Vector3>()
	{
		{ "Right",   Vector3.right },
		{ "Left",    Vector3.left },
		{ "Up",      Vector3.up },
		{ "Down",    Vector3.down },
		{ "Forward", Vector3.forward },
		{ "Back",    Vector3.back }
	};
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi select drop down list for enum
In my question I mean that I want to get multiselect dropdown list with single return value. It was just the example of...
Read more >
How to select multiple values from enum in a dropdown?
Hi, In my application, I have one enum with five values. Now I want to select multiple values from the dropdown. How can...
Read more >
Order by query optimization for multi select data (enum)
Below is an example of how you can return the ordered list using your new structure. What is missing from the database design...
Read more >
Multiple enum select from inspector
Hi guys I'm quite new to c# and trying to get my head round the use of enums , I'm currently using a...
Read more >
Populating a List/Multi-Select Field from the API
With the API, I've noticed I cannot define values in a multi-select field that have not already been created, hence when I attempt...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found