54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class SkinShopItem : MonoBehaviour
|
|
{
|
|
public Image spaceshipImg;
|
|
public Image backgroundImg;
|
|
public Button buyBtn;
|
|
public Button equipBtn;
|
|
public GameObject equippedIndicator;
|
|
public new string name;
|
|
public int price;
|
|
public TMPro.TMP_Text nameTxt;
|
|
|
|
void Start(){
|
|
buyBtn.onClick.AddListener(onBuy);
|
|
equipBtn.onClick.AddListener(onEquip);
|
|
}
|
|
|
|
public void Set(SkinShopItemData data){
|
|
name = data.name;
|
|
nameTxt.text = data.name;
|
|
price = data.price;
|
|
|
|
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
|
|
spaceshipImg.sprite = data.image;
|
|
buyBtn.GetComponentInChildren<TMPro.TMP_Text>().text = price.ToString();
|
|
buyBtn.interactable = DBmanager.Metal >= price;
|
|
|
|
buyBtn.gameObject.SetActive(!(DBmanager.SkinsPurchased.Contains(name) || price<=0));
|
|
equipBtn.gameObject.SetActive(!buyBtn.gameObject.activeSelf);
|
|
|
|
if(SkinShopManager.GetEquipedSkin() == name){
|
|
equipBtn.gameObject.SetActive(false);
|
|
equippedIndicator.SetActive(true);
|
|
}else{
|
|
equippedIndicator.SetActive(false);
|
|
}
|
|
}
|
|
|
|
void onEquip(){
|
|
SkinShopManager.EquipSkin(name);
|
|
SkinShopManager.instance.Populate();
|
|
}
|
|
|
|
void onBuy(){
|
|
SkinShopItemData data = new SkinShopItemData(){name=name, price=price};
|
|
DBmanager.PurchaseSkin(data);
|
|
|
|
SkinShopManager.instance.Populate();
|
|
}
|
|
}
|