I'm trying to create a "sims-like" context menu when an item / game object is clicked.
This comes as an add-on question from this question: How to design context menus based on whatever the object is?
Specifically:
Each object of class Item would have a list of components like Equipable, Edible, Sellable, Drinkable, etc. An item can have one or none of each component (for example, a helmet made of chocolate would be both Equipable and Edible, and when it is not a plot-critical quest item also Sellable). The programming logic which is specific to the component is implemented in that component. When the user right-clicks on an item, the components of the item are iterated and context-menu entries are added for each component which exists. When the user selects one of these entries, the component which added that entry processes the option.
You could represent this in your XML-file by having a sub-node for each component. Example:
<item>
<name>Chocolate Helmet</name>
<sprite>helmet-chocolate.png</sprite>
<description>Protects you from enemies and from starving</description>
<edible>
<taste>sweet</taste>
<calories>2560</calories>
</edible>
<equipable>
<slot>head</slot>
<def>20</def>
</equipable>
<sellable>
<value>120</value>
</sellable>
</item>
When I read this, it reminds me of an interface in programming. My question is, how do you implement this? Perhaps a better question is "is the answer still valid" but it does seem relevant to me.
What have I tried?
Nothing at this point, because I'm not sure where to start. Given the example above, I'd guess that Item
would have a list of... interfaces? that it could implement? This is why I am a bit confused.
I want to add, this isn't just a UI issue. I found a few radial menus in the store, my issue is how to populate the menu depending on what game object is clicked.
GetComponents<IContextMenuExposed>()
— did you run into any specific obstacle making this component system work for you? \$\endgroup\$