Creating a UI based on selected gameObject

Here is my case. I’m working on a RTS game shell. So for instance, I have building and unit.

Building enable creating new unit and upgrade
And unit has action.

Here is the situation, I want create UI action bar based on selected unit/building. The selection work fine. I can access to the selected unit/building list… actually I’m having a Ui panel showing icon of each unit selected unit and Incan click on the icon to select the single unit.

Movement work for group such as any rts.

Now what I want do is an action bar based on the selected unit/building.

Example : if the selection is a mix of different unit type, juste the regular move, stop,hold,attack button will show up.
If the selection contain only 1 type of unit I want for demo show all the common action + the special ability of this unit type.

I’m not looking for an existing implementation but discuss about a good way for achieving it.

Does for single unit selection what I was doing was having a prefab with all the UI element and reference the actions to a specific unit (the selected unit).

But obviously it’s not suitable for multiple selection.

I can instantiate any UI element at runtime but before doing it, if anyone has experience with that, I will appreciate advice.

Either have different UIs for each agent type, or else have the agents contain a piece of data saying what they need to be visible in the common shared-by-all UI, then turn the right parts on / off.

Ideally the agent scripts should express interfaces indicating what they can do, then your UI code can simply introspect the agents and ask which interfaces they express. You want to avoid hard-coding “Agent X does actions A,B, and C” stuff in code. Put that into data to the extent possible.

Your choices are to:

  • show the superset of features and have agents that can’t do certain things simply ignore them
  • show only the shared subset of features that all agents express

Whatever path you choose it will likely change a LOT as you move forward and learn more about your game, so don’t over-agonize on it today. Pick something and move forward. If it begins to cause you pain, refactor when you know more.

2 Likes

Thank you for your comment. Will think about that.