Hi!
I’m making a point and click game, and I want to design a context menu that opens when clicking on an item in the inventory bar. (ignore the ugliness, it’s all for testing at the moment)
So far, i have managed to instantiate a prefab UI image with a script “ContextMenu” (bottom left blank UI Image).
I want the context menu to instantiate specific buttons based on available interactions with the right clicked inventory item.
For example, with the current parts in the inventory bar, you can “Use” them, and “Examine” them. They have a script on them that implements the interfaces IUsable and IExaminable, each with a method I want to hook up to a button via scripting.
I would like to avoid writing code such as
public void Setup(InventoryItem item)
{
var examinableItem = item as IExaminable;
//create a button
button1.GetComponent<Button>().onClick.AddListener(() =>
examinableItem.Examine());
var useableItem = item as IUsable;
//create a button
button2.GetComponent<Button>().onClick.AddListener(() =>
examinableItem.Use());
}
Do you have any suggestions?
Thanks for your time!