コード例 #1
0
    public void AddItemToShoppingCart(ItemInstance newItem)
    {
        int indexOf = shoppingCart.IndexOf(newItem);

        if (indexOf >= 0)
        {
            shoppingCart[indexOf].stock += newItem.stock;
        }
        else
        {
            ItemInstance newItemInstance            = new ItemInstance(newItem);
            ShoppingCartTransactionButton newButton = Instantiate(buttonPrefab, parent);
            newButton.HeldItem = newItemInstance;
            shoppingCart.Add(newItemInstance);
        }
        costOfTransaction += newItem.stock * newItem.item.baseSellPrice;
    }
コード例 #2
0
    public void RemoveFromShoppingCart(ShoppingCartTransactionButton itemToRemove, int howMany)
    {
        int indexOf = shoppingCart.IndexOf(itemToRemove.HeldItem);

        if (indexOf >= 0)
        {
            if (itemToRemove.HeldItem.stock - howMany <= 0)
            {
                howMany            = itemToRemove.HeldItem.stock;
                costOfTransaction -= howMany * itemToRemove.HeldItem.item.baseSellPrice;
                shopPanel.ReturnItem(itemToRemove.HeldItem, howMany);
                itemToRemove.HeldItem.stock = 0;
                shoppingCart.RemoveAt(indexOf);
            }
            else
            {
                costOfTransaction -= howMany * itemToRemove.HeldItem.item.baseSellPrice;
                shopPanel.ReturnItem(itemToRemove.HeldItem, howMany);
                itemToRemove.HeldItem.stock -= howMany;
            }
        }
    }