88 lines
2.0 KiB
C#
88 lines
2.0 KiB
C#
using System;
|
|
using UFS2.Tokens;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TokenPrefabItem : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Text amountText;
|
|
|
|
[SerializeField]
|
|
private Text timeText;
|
|
|
|
[SerializeField]
|
|
private Image tokenImage;
|
|
|
|
[SerializeField]
|
|
private Sprite[] tokensSprites;
|
|
|
|
[SerializeField]
|
|
private BoostToken token;
|
|
|
|
public void Initialize(BoostToken tokenvalue)
|
|
{
|
|
token = tokenvalue;
|
|
amountText.text = $"x{token.amount}";
|
|
timeText.text = string.Format("{0} {1}", token.durationTime, LanguageManager.Instance.GetText("MINUTES_LONG"));
|
|
switch (token.type)
|
|
{
|
|
case BoostToken.tokenType.TokenXP:
|
|
tokenImage.sprite = tokensSprites[0];
|
|
break;
|
|
case BoostToken.tokenType.TokenCash:
|
|
tokenImage.sprite = tokensSprites[1];
|
|
break;
|
|
}
|
|
if (token.amount == 0)
|
|
{
|
|
base.gameObject.GetComponent<Button>().interactable = false;
|
|
}
|
|
}
|
|
|
|
public void UseToken()
|
|
{
|
|
BoostTokens.GetBoostToken(token.durationTime, token.type).SubAmount(1);
|
|
RefreshData(token);
|
|
switch (token.type)
|
|
{
|
|
case BoostToken.tokenType.TokenXP:
|
|
try
|
|
{
|
|
GameManager.Instance._playerData.AddExpBoostTime(token.durationTime * 60);
|
|
}
|
|
catch (Exception message2)
|
|
{
|
|
Debug.LogError(message2);
|
|
}
|
|
break;
|
|
case BoostToken.tokenType.TokenCash:
|
|
try
|
|
{
|
|
GameManager.Instance._playerData.AddCashBoostTime(token.durationTime * 60);
|
|
}
|
|
catch (Exception message)
|
|
{
|
|
Debug.LogError(message);
|
|
}
|
|
break;
|
|
default:
|
|
Debug.LogError("Token dont have a Type");
|
|
break;
|
|
}
|
|
UnityEngine.Object.FindObjectOfType<TokensPanel>().InitializeBoostImages();
|
|
}
|
|
|
|
private void RefreshData(BoostToken token)
|
|
{
|
|
amountText.text = $"x{token.amount}";
|
|
timeText.text = string.Format("{0} {1}", token.durationTime, LanguageManager.Instance.GetText("MINUTES_LONG"));
|
|
if (token.amount == 0)
|
|
{
|
|
base.gameObject.GetComponent<Button>().interactable = false;
|
|
base.gameObject.GetComponent<Hover>().enabled = false;
|
|
base.gameObject.GetComponent<Image>().sprite = base.gameObject.GetComponent<Hover>().normalImage;
|
|
}
|
|
}
|
|
}
|