#Button events?

1 messages · Page 1 of 1 (latest)

vagrant oracle
#

Hi guys, i am trying to figure out how to structure my code for a particular thing.
I am making a game where you have a node grid, and when you click on a node, it creates a button (not an UI button, just a custom button class because my buttons are not just UI into a canvas) for each action possible on that node. For example, spawning a building, or selling that building, upgrading that building etc.
But there are a few things i am struggling to do :

#

The first one is :
I ask my node to "calculate" which action is aviable for itself and return a "NodeAction" list to my button spawner and it creates a button for each aviable action. Sometimes, one action is simple and will always be the same (selling the building for example, nothing fancy here), but for spawning a building, i need my "build" button to create sub-buttons for each buildable building (Depending if the player has unlocked or can afford the building, or if an other building needs to be built in the first place to upgrade it). How do i manage the creation of submenus, and how do can i structure my architecture for supporting submenus, and maybe submenus of submenus in a smart way?

#

The second one is :
For each available action for the node, i need to tell the button what to do when it is triggered. So, my "NodeAction" are actually scriptable objects (because they also contain ref to the sprite for the button, name of the action, or a tooltip on mouse over for the button etc), in which i'd like to bind a particular method in the inspector to be called when the button is pressed. I figured i could use UnityActions. The problem is, the objects my scripts are attached to is in the scene hierarchy and i can't drag them onto the scriptable object. Can i just drag a script into it? At first i was thinking of doing something like create an abstract class "Interaction" with an "interact" method into it, and each time the button is pressed, it would call "interact" of the linked "Interaction". But then, i can't expose my "Interaction" in the inspector to drag into the NodeAction scriptable object. Any thoughts on this?