// Called when an item's buy button is clicked.
        private void OnBuy(BuyInventoryItem item)
        {
            if (currency < item.Cost)
            {
                return;
            }

            DateTime deliveryTime = DateTime.Now.ToLocalTime() + TimeSpan.FromMinutes(item.Minutes);

            console.SendNotification(item.Title, item.Description, deliveryTime, reschedule: true,
                                     smallIcon: item.ItemData.IconId, largeIcon: item.ItemData.IconId);

            pendingItems.Add(new PendingInventoryItem
            {
                DeliveryTime = deliveryTime,
                ItemData     = item.ItemData
            });

            // Store the item's cost before deducting it, so item can be updated in SetCurrency based on its new cost
            int cost = item.Cost;

            item.Cost    += item.ItemData.CostIncrease;
            item.Minutes += item.ItemData.CreationTimeIncrease;
            item.OnBuySuccess(deliveryTime);

            SetCurrency(currency - cost);
            UpdateControls();
        }
        // Called when an item was delivered.
        private void OnDeliveredItem(InventoryItemData itemData)
        {
            // Add the item to the stats area.
            if (items.TryGetValue(itemData, out InventoryItem item))
            {
                // Update existing item of the same type
                item.OnReceivedItem();
            }
            else
            {
                item = Instantiate(itemPrefab, contentHolder);
                items.Add(itemData, item);
                item.Initialise(itemData);
            }

            // Let buy items know an item was delivered
            for (int i = 0, len = buyItems.Count; i < len; i++)
            {
                BuyInventoryItem buyItem = buyItems[i];
                if (buyItem == null)
                {
                    continue;
                }
                buyItem.OnDeliveredItem(itemData);
            }
        }
        private void Awake()
        {
            // Create the buy items
            for (int i = 0, len = itemsData.Length; i < len; i++)
            {
                InventoryItemData data = itemsData[i];
                BuyInventoryItem  item = Instantiate(buyItemPrefab, buyContentHolder);
                item.Initialise(data, OnBuy);
                buyItems.Add(item);
            }

            SetCurrency(initialCurrency);
            UpdateControls();
            ShowNewsFeedLoadingIcon(false);
        }
        private void SetCurrency(float newCurrency)
        {
            int oldCurrency = (int)currency;

            currency = newCurrency;
            if (oldCurrency == (int)currency || buyItems.Count <= 0)
            {
                return;
            }

            // Let buy items know the currency changed
            int changedCurrency = (int)currency;

            for (int i = 0, len = buyItems.Count; i < len; i++)
            {
                BuyInventoryItem item = buyItems[i];
                if (item == null)
                {
                    continue;
                }
                item.OnCurrencyChanged(changedCurrency);
            }
        }