using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class SkinShopItem : MonoBehaviour { public Image spaceshipImg; [Tooltip("In order of: normal, rare, legendary. 3 items required")] public GameObject[] banners; public Image frame; public bool Available; // public GameObject notPurchasedIndicator; public SkinShopItemData skinData; [Header("Stats")] public TMP_Text txtLevel; public TMP_Text txtEnergyGain; public TMP_Text txtSpeed; public TMP_Text txtBoostConsumption; public void Set(SkinShopItemData data, bool available){ skinData = data; // newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor); if(available){spaceshipImg.sprite = data.image;} spaceshipImg.color = available ? Color.white : Color.black; Available = available; UpdateFrame(); if(data.price_metal <=0 && data.price_gold <=0){ banners[0].SetActive(true); banners[1].SetActive(false); }else{ banners[0].SetActive(false); banners[1].SetActive(data.skinType== SkinType.Base); } banners[2].SetActive(data.skinType== SkinType.Rare); banners[3].SetActive(data.skinType== SkinType.Legendary); //Level txtLevel.text = ""; txtEnergyGain.transform.parent.gameObject.SetActive(available); txtSpeed.transform.parent.gameObject.SetActive(available); txtBoostConsumption.transform.parent.gameObject.SetActive(available); if(available){ int curLevel = DBmanager.SkinsPurchased[data.name]; RocketLevel level = SkinShopManager.GetStatsForRarity(data)[curLevel]; txtLevel.text = "Level " +(curLevel+1); txtEnergyGain.text = level.moonMultiplier.ToString(); txtSpeed.text = (level.speedMultiplier * 100).ToString("n0") + "%"; txtBoostConsumption.text = (level.boostConsumption * 100).ToString("n0") + "%"; } } public void UpdateFrame(){ if(SkinShopManager.GetEquipedSkin() == skinData.name){ frame.enabled=true; frame.color = Color.cyan; }else{ frame.enabled=false; } if(!DBmanager.SkinsPurchased.ContainsKey(skinData.name)){ frame.color = Color.red; // notPurchasedIndicator.SetActive(true); // notPurchasedIndicator.GetComponentInChildren().text = skinData.price.ToString(); }else{ // notPurchasedIndicator.SetActive(false); } if(!Available){ // notPurchasedIndicator.SetActive(false); } } public void OnClick(){ SkinShopManager.instance.SelectItem(skinData,Available); } public void OnSelectionChanged(string selectedItem){ if(selectedItem == skinData.name){ frame.enabled=true; }else{ frame.enabled = false; } if(SkinShopManager.GetEquipedSkin() == skinData.name){ frame.enabled = true; } } // void onEquip(){ // SkinShopManager.EquipSkin(name); // SkinShopManager.instance.Populate(); // } // void onBuy(){ // SkinShopItemData data = new SkinShopItemData(){name=name, price=price}; // DBmanager.PurchaseSkin(data); // SkinShopManager.instance.Populate(); // } }