Repository navigation
Conversation
This just optionally modifies the text being drawn in the dropdown, so that the user can easily prefix or suffix options with "decoration".
af0d396 to
f06466d
Compare
|
Updated this PR to not conflict with base. |
|
FWIW I feel this is too specific to require its own first-class support. I think it would be more flexible to add a constructor for private readonly int[] _baudRates { 300, 1200, /* ... */ };
private DropdownList<int> BaudRateOptions =>
new DropDownList<int>(_baudRates.Select(b => new KeyValuePair($"{b} baud", b)); |
|
I like that for However my approach here was to keep the editor-specific metadata out of the class definition itself. By having it only live in the attribute, it let me keep the class "cleaner" in the sense it keeps the members related to that choice as only needing the serialized field(s) plus the options array. I realize the distinction there is potentially quite slim; I'm just much more a fan of having as much of my inspector-related data to live in attributes rather than inspector-specific properties that live on the class directly. |
|
Could always do: #if UNITY_EDITOR
private readonly int[] _baudRates { 300, 1200, /* ... */ };
private DropdownList<int> BaudRateOptions =>
new DropDownList<int>(_baudRates.Select(b => new KeyValuePair($"{b} baud", b));
[Dropdown(nameof(BaudRateOptions)]
#endif
[SerializeField] int _baudRate = 300;Or even: #if UNITY_EDITOR
private DropdownList<int> BaudRateOptions => MyNaUtility.Suffix(new [] {
300,
1200,
// ...
}, " baud");
[Dropdown(nameof(BaudRateOptions)]
#endif
[SerializeField] int _baudRate = 300;The reason I'm proposing this is because suffix and prefix are just a small subset of value -> label string conversions that a user could conceivably want. |
I had to give some real thought to this, because you're completely spot on. I think my affinity for doing it the way I had was due mostly to a desire to keep the user's interface to be mostly similar to a non-modified string conversion. (And to not need Allowing the user to provide an the actual format string lets them provide a mutation that includes any sort of custom formatting, but keeps the attribute usage clean and straightforward. It definitely doesn't provide as much potential flexibility as your I pushed a commit that changes the implementation to this. |
[Dropdown][Dropdown]
[Dropdown][Dropdown]
This just optionally modifies the text being drawn in the dropdown, so that the user can easily prefix or suffix options with "decoration".
My use case was to decorate a list of baud rates, but not wanting to have the entire setup with a
DropdownList<T>:However, the prefix and suffix decorations do still work with the
DropdownList<T>: