示例#1
0
    //If you select an object, turn on the overview and set the correct part. If it is selected already, hide the overview
    public void SelectPart(PartItemConnector _part)
    {
        if (partItemsList.Count > 0 && selectedPart >= 0)
        {
            if (partItemsList[selectedPart] == _part)
            {
                selectedPart = -1;
                partOverviewObj.SetActive(false);
                return;
            }
        }

        for (int i = 0; i < partItemsList.Count; i++)
        {
            if (partItemsList[i] == _part)
            {
                selectedPart = i;
                partOverviewObj.SetActive(true);
                partCostText.text = "Cost:\n" + "$" + _part.partItem.Cost;

                if (_part.isPurchased)
                {
                    partBuyButton.interactable = false;
                    ColorBlock colors = new ColorBlock();
                    colors.normalColor     = Color.red;
                    colors.disabledColor   = Color.red;
                    colors.colorMultiplier = 1;
                    partBuyButton.colors   = colors;
                    partBuyButton.transform.GetComponentInChildren <Text>().text = "Purchased";
                    return;
                }
                else if (_part.partItem.Cost > player.Money)
                {
                    ColorBlock colors = new ColorBlock();
                    colors.normalColor         = Color.green;
                    colors.disabledColor       = Color.gray;
                    colors.colorMultiplier     = 1;
                    partBuyButton.colors       = colors;
                    partBuyButton.interactable = false;
                    partBuyButton.transform.GetComponentInChildren <Text>().text = "Too Expensive";
                }
                else if (!partBuyButton.interactable)
                {
                    partBuyButton.interactable = true;
                    ColorBlock colors = new ColorBlock();
                    colors.normalColor     = Color.green;
                    colors.disabledColor   = Color.gray;
                    colors.colorMultiplier = 1;
                    partBuyButton.colors   = colors;
                    partBuyButton.transform.GetComponentInChildren <Text>().text = "Purchase";
                }

                partBuyButton.onClick.RemoveAllListeners();
                partBuyButton.onClick.AddListener(delegate { PurchasePart(_part); });
                return;
            }
        }
        selectedPart = -1;
        partOverviewObj.SetActive(false);
    }
示例#2
0
    void PopulatePartsList()
    {
        int neededItems = 6;

        for (int i = partItemsList.Count; i > 0; i--)
        {
            neededItems--;
            if (partItemsList[i - 1].isPurchased)
            {
                neededItems++;
                PartItemConnector _part = partItemsList[i - 1];
                partItemsList.Remove(_part);
                _part.gameObject.SetActive(false);
                Destroy(_part.gameObject);
            }
        }
        for (int n = 0; n < neededItems; n++)
        {
            partItemsList.Add(NewPartCard());
        }
    }
示例#3
0
    public void PurchasePart(PartItemConnector _part)
    {
        if (player.Money - _part.partItem.Cost >= 0 && !_part.isPurchased && player.PartsInventory.ItemCount < player.PartsInventory.MaxItems)
        {
            player.Money     -= _part.partItem.Cost;
            _part.isPurchased = true;
            player.AddPart(_part.partItem);

            _part.purchasedOverlay.SetActive(true);
            _part.partIcon.color = Color.black;

            partBuyButton.interactable = false;
            ColorBlock colors = new ColorBlock();
            colors.normalColor     = Color.red;
            colors.disabledColor   = Color.red;
            colors.colorMultiplier = 1;
            partBuyButton.colors   = colors;
            partBuyButton.transform.GetComponentInChildren <Text>().text = "Purchased";
            uiAudio.PlaySound(UIsounds.Purchase);
        }
    }
示例#4
0
    //Spawns a new Spare Part item card
    PartItemConnector NewPartCard()
    {
        Transform spawnPos = partItemHolder1.transform;

        if (partItemHolder1.gameObject.GetComponentsInChildren <PartItemConnector>().Length < 3)
        {
            spawnPos = partItemHolder1.transform;
            //print(partItemHolder1.gameObject.GetComponentsInChildren<PartItemConnector>().Length);
        }
        else
        {
            spawnPos = partItemHolder2.transform;
        }

        PartItemConnector newPartCard = Instantiate(partItemPrefab, spawnPos).GetComponent <PartItemConnector>();

        newPartCard.shopMain           = this;
        newPartCard.purchaseItemButton = partBuyButton;

        newPartCard.partItem = partDataHolder.GetRandomPart();

        return(newPartCard);
    }