public void RegisterToShopBuyEvent()
{
var myPlayerGameobject = gameObject;
Opsive.Shared.Events.EventHandler.RegisterEvent<ShopGeneric<CurrencyCollection>, ItemInfo, Action<bool>>(
myPlayerGameobject,
EventNames.c_InventoryGameObject_OnBuyAddItem_Shop_ItemInfo_ActionBoolSucces,
HandleOnShopBuy);
}
private void HandleOnShopBuy(ShopGeneric<CurrencyCollection> shop, ItemInfo itemBought, Action<bool> result)
{
// If you want to add the item to the Inventory do this, if not Ignore
{
var playerInventory = m_Inventory;
var itemCollection = shop.GetItemCollectionToAddItemTo(playerInventory, itemBought);
if (itemBought.Item.IsMutable && itemBought.Item.IsUnique) {
for (int i = 0; i < itemBought.Amount; i++) {
itemCollection.AddItem(InventorySystemManager.CreateItem(itemBought.Item));
}
} else {
itemCollection.AddItem(itemBought);
}
}
// Here you can get your pet and instantiated.
var petPrefab = itemBought.Item.GetAttribute<Attribute<GameObject>>("PetPrefab").GetValue();
var instance = Instantiate(petPrefab);
//Important don't forget to say that the buying was successful
result?.Invoke(true);
}