Cost Calculator (Lists with thousands of values)

I’m working on a Unity project that involves creating a cost calculator for a client’s products. To calculate the square footage of product, I’d like to implement to dropdown menu’s and have their values be multiplied with each other to get a result.

The problem is I’d like to populate the menu with a lot of values (from 1 to 3,000). I’m obviously not going to type out 3,000 numbers in a list and I haven’t been able to find through my searches how to populate a dropdown menu with that many values. Below are what I’d like to have in each dropdown menu.

Dropdown menu 1 (length): 1 through 3,000
Dropdown menu 2 (width): 6 through 3,000 in multiples of 6 (6, 12, 18, 24, 30, etc).

Any advice would be greatly appreciated. Thank you in advance.

And you think your client wants to scroll through 3,000 numbers in a list? My advice is to not have a dropdown menu with 3,000 entries, that’s an unmitigated UI nightmare. Just use a text field!

That said, if you must, it should be straightforward to populate it in Start(). Assuming you’re using Unity UI’s builtin dropdown component, there’s some sample code here for adding dropdown values in code.

1 Like

First, thank you for your reply, I’ll take a look a the link you’ve provided.

Second, no, I don’t think they really want to scroll through 3,000 numbers, but that’s how they want it formatted for whatever reason, not my call. Maybe they’d allow for an input text field for the first dropdown, but for the second one they for sure want a dropdown. I don’t believe most of their clients are really going to be scrolling past a few hundred anyway.

Oh, yeah. I do know the “client makes a really dumb request” thing. In your place I’d be prepared for the client to say “why is this a dropdown, this is terrible!” because that’s just sort of what clients do… so maybe have a text field there as well wired up and ready to go but disabled, so you can be all “I anticipated this change and here it is”.

Are they really going to be searching by number? I mean, if they want a long-handled Phillips screwdriver wouldn’t they type one of those words? Or will they know Tools start with 25, so will want to enter that, and “phillips” and see a list of 25xxx-coded items with that keyword? As RayS writes, it can take a while to understand the real “use cases”.

1 Like

I’d talk to the client about this issue. Maybe you can organize the list into categories and sub categories, so it could be more easily navigated through drop downs. Maybe you could do a text search for matching items. A single 3k drop down is just not going to work as far as usability, and the client will blame the bad design on you even if you are doing exactly what you think they want.

just use a loop to populate the dropdowns

Thank you all for the feedback. I’ve considered everything you all have mentioned and I’m think I’m going to try to input fields instead of dropdown menus and see what the client thinks (for the record, the client is not an old timey oil baron, so if they don’t like the concept, they’ll politely ask me try again with the dropdown menus).

Also, to be clear, the numbers are measurements (feet), not products. The product is a roll (let’s say carpet), that can be any length up to 3000ft and widths of 6ft (6, 12, 18, 24, 36, 42, 48, etc) up to 30000. So it’s not a product search, it’s a calculator.

So the first input field is simple, enter any number from 1 to 3,000. The second input field should only accept multiples of 6. “OnValueChanged” only takes a string (as far as I’ve seen), but I’m using ints. Is there a way to make the field only accept multiples of 6?

It’ll send you a string, and then you can use int.Parse(text) to parse that into an int, round to the nearest 6, and then set inputField.text to the rounded number.

(Note: use the onEndEdit event and not the onChange event; otherwise, when the user types say “114” it will round the “1” to “0” as the user types in numbers and not let them type the actual number)

I’m getting a bad feeling about this project. The client wanted to multiply 2 numbers together, with the only weirdness that one must be a multiple of 6, and decided it should use dropdowns? Are customers going to be all “hmmm…437 is too expensive, but 433 isn’t long enough. I wonder what numbers come between them? Oh, excellent – the dropdown has them!! 434? You learn something new every day”.

Maybe they really want a slow slider, like how the Unity Editor does it. Just slow enough they can easily get +1, +1, +1 … by sliding to fine-tune a typed-in value.

If I were designing this UI, those would definitely be text boxes rather than dropdowns. But sometimes the client is foolish and won’t accept advice. My boss has a story about a client who demanded stringently that UI screens look exactly like the pictures they provided, and refused to listen until he actually built the screens and the client realized there was no way to get to a certain screen. (“How do you get to this screen?” “We don’t know. We followed your instructions exactly, but they didn’t include any button that leads to that screen. Can we discuss changes now?”)

I would further suggest that if you type a number that is not a multiple of 6, a message appears next to the text box alerting you to the issue, maybe with a button labeled “round” that (if pressed) will convert the entered value into the closest multiple of 6.

I would NOT suggest rounding automatically, because if the user tried to enter a multiple of 6 but made a typo such as inverting two digits, then rounding will make it harder for the user to figure out what went wrong or how to fix it. You should only change the user’s entered values with their approval.

Also, the message should appear either while you are typing or as soon as you de-select the input box, rather than waiting until you try to submit the form. (I believe you can implement those using OnValueChange and OnEndEdit callbacks, respectively; but if you run into problems, neither version would be hard to implement using an Update function, either.)

If the client doesn’t like typing and there are only a few numbers that are commonly-used (e.g. if 95% of users will ask for a multiple of 6 that is 30 or less), you could consider adding “shortcut” buttons for those numbers that fill the text field with a single click. (Note that the available shortcuts don’t need to be consecutive; you can set them to whatever values are actually commonly-used.)

this is to the level that you should use a google sheet, unity seems overkill if you just want to multiply 2 numbers

I think we’re working on the assumption that this is not the only thing this app does…

Text fields for sure, with the error-checking that dropdowns would otherwise provide via restricted selections.
On a side note, I’m trying to wrap my brain around a 3000 x 3000 roll of carpet :eyes: