Game Development Reference
In-Depth Information
selectedButton = button;
}
This will simply clear the existing selection if there is one and then track the new selec-
tion. If the user has simply cleared their last selection, then this would just be
null
.
Now we just need to be able to actually select a button, but first we need a few things.
Updating the BattleManager state with selections
Now that the command bar can select and deselect buttons, we need to be able to tell the
BattleManager
state that the player has selected a weapon. For this, we'll use mes-
saging as there is no direct relationship between the command bar and the
BattleMan-
ager
state.
First we'll need to beef up the
MessagingManager
script with a new event we want to
publish as we have done previously with the Dialog and UI events.
So, open up the
MessagingManager
script and add the following:
private List<Action<InventoryItem>> inventorySubscribers =
new List<Action<InventoryItem>>();
// Subscribe method for Inventory manager
public void SubscribeInventoryEvent
(Action<InventoryItem> subscriber)
{
if (inventorySubscribers != null)
{
inventorySubscribers.Add(subscriber);
}
}
// Broadcast method for Inventory manager
public void BroadcastInventoryEvent(InventoryItem itemInUse)
{
foreach (var subscriber in inventorySubscribers)
{
subscriber(itemInUse);
}