protected void UpdateSideCar(int offset) { // Gets info on the current car. GameController.AdditionalCar car = GameController.Instance.GetAdditionalCar(currentCar + offset - 1); // Gets the components for the correct car. Image carImage = (offset == 1) ? leftCarUI.carImage : rightCarUI.carImage; Image slotImage = (offset == 1) ? leftCarUI.slotImage : rightCarUI.slotImage; GameObject mainCarGraphics = (offset == 1) ? leftCarUI.mainCarGraphics : rightCarUI.mainCarGraphics; GameObject additionalCarGraphics = (offset == 1) ? leftCarUI.additionalCarGraphics : rightCarUI.additionalCarGraphics; // For the main car. if (currentCar + offset == 0) { carImage.color = nonFocusedColor; // Shows the correct car graphics. mainCarGraphics.SetActive(true); additionalCarGraphics.SetActive(false); // For the additional cars. } else { // Checks if the car has been bought and sets the upgrades available. bool boughtCar = (car != null); SlotFitInfo currentSlot = (currentCar != 0 && car != null) ? GameController.Instance.GetSlotFit(car.slotFitId) : null; // Sets the UI. carImage.color = boughtCar ? nonFocusedColor : nonBoughtColor; Color slotcolor = boughtCar ? nonFocusedColor : new Color(0, 0, 0, 0); if (currentSlot == null || currentSlot.id == "none") { slotcolor.a = 0; } slotImage.color = slotcolor; slotImage.sprite = (boughtCar && currentSlot != null) ? currentSlot.sprite : null; // Shows the correct car graphics and hides invalid cars. bool validCar = (currentCar + offset) >= 0 && (currentCar + offset) <= maxAdditionalCars; mainCarGraphics.SetActive(false && validCar); additionalCarGraphics.SetActive(true && validCar); } }
public void Upgrade() { // Gets the upgrade to be made. GameController.AdditionalCar car = GameController.Instance.GetAdditionalCar(currentCar - 1); SlotFitInfo upgrade = GameController.Instance.GetSlotFitUpgrade(car.slotFitId); // No upgrades. if (upgrade == null) { return; } // Spends the money. GameController.Instance.Money -= upgrade.price; // Gives the upgrade. GameController.Instance.UpgradeCar(currentCar - 1, upgrade.id); UpdateUI(); }
protected void UpdateFocusedCarUI() { // Gets info on the current car. GameController.AdditionalCar car = GameController.Instance.GetAdditionalCar(currentCar - 1); // Sets the selected car UI. focusedCarUI.carName.text = focusedCarUI.carNames[currentCar]; // Checks if the car has been bought. bool boughtCar = (car != null); // Gets the current slot and upgrades. SlotFitInfo currentSlot = (currentCar != 0 && car != null) ? GameController.Instance.GetSlotFit(car.slotFitId) : null; SlotFitInfo upgrade = (currentCar != 0 && car != null) ? GameController.Instance.GetSlotFitUpgrade(car.slotFitId) : null; // Gets prices. int repairPrice = (boughtCar) ? Mathf.RoundToInt(100 - car.health) : 0; int upgradePrice = (upgrade != null) ? upgrade.price : -100; // Sets the store interaction buttons UI. focusedCarUI.repairButton.interactable = (repairPrice > 0 && repairPrice <= GameController.Instance.Money); focusedCarUI.upgradeButton.interactable = (upgrade != null && upgradePrice <= GameController.Instance.Money); focusedCarUI.buyButton.interactable = (carPrice <= GameController.Instance.Money); // Sets the prices and text colors. focusedCarUI.repairPriceText.text = (repairPrice > 0) ? repairPrice + "$" : "--"; focusedCarUI.upgradePriceText.text = (upgrade != null) ? upgradePrice + "$" : "--"; focusedCarUI.buyPriceText.text = carPrice + "$";; focusedCarUI.repairPriceText.color = (repairPrice <= GameController.Instance.Money) ? Color.green : Color.red; focusedCarUI.upgradePriceText.color = (upgradePrice <= GameController.Instance.Money) ? Color.green : Color.red; focusedCarUI.buyPriceText.color = (carPrice <= GameController.Instance.Money) ? Color.green : Color.red; // For the main car. if (currentCar == 0) { focusedCarUI.carImage.color = Color.white; focusedCarUI.healthBarFill.rectTransform.localScale = Vector3.one; focusedCarUI.mainCarOptions.SetActive(true); focusedCarUI.additionalCarOptions.SetActive(false); focusedCarUI.buyCarOptions.SetActive(false); focusedCarUI.mainCarGraphics.SetActive(true); focusedCarUI.additionalCarGraphics.SetActive(false); // For the additional cars. } else { // Sets the health bar. focusedCarUI.healthBarFill.rectTransform.localScale = boughtCar ? new Vector3(car.health / 100.0f, 1, 1) : new Vector3(0, 1, 1); // Sets the UI. focusedCarUI.carImage.color = boughtCar ? Color.white : nonBoughtColor; Color slotcolor = boughtCar ? Color.white : new Color(0, 0, 0, 0); if (currentSlot == null || currentSlot.id == "none") { slotcolor.a = 0; } focusedCarUI.slotImage.color = slotcolor; focusedCarUI.slotImage.sprite = (boughtCar && currentSlot != null) ? currentSlot.sprite : null; // Shows the correct car options. focusedCarUI.mainCarOptions.SetActive(false); focusedCarUI.additionalCarOptions.SetActive(boughtCar); focusedCarUI.buyCarOptions.SetActive(!boughtCar); // Shows the correct car graphics. focusedCarUI.mainCarGraphics.SetActive(false); focusedCarUI.additionalCarGraphics.SetActive(true); } // Enables/disables the next and previous buttons when necessary. nextButton.interactable = (currentCar < maxAdditionalCars && (currentCar == 0 || car != null)); previousButton.interactable = (currentCar != 0); }