53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameModeAvailableActualizator : MonoBehaviour
|
|
{
|
|
public string PriceKey;
|
|
public bool readyToBlink = false;
|
|
public float frequency = 5;
|
|
public Gradient gradient;
|
|
public Graphic graphic;
|
|
|
|
private void OnEnable()
|
|
{
|
|
RefreshState();
|
|
SingleWallet.onCoinAdded.AddListener(RefreshState);
|
|
SingleWallet.onCoinRemoved.AddListener(RefreshState);
|
|
SettingsManager.OnSettingsChanged.AddListener(RefreshState);
|
|
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
SingleWallet.onCoinAdded.RemoveListener(RefreshState);
|
|
SingleWallet.onCoinRemoved.RemoveListener(RefreshState);
|
|
SettingsManager.OnSettingsChanged.RemoveListener(RefreshState);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (readyToBlink) Blink();
|
|
}
|
|
|
|
private void Blink()
|
|
{
|
|
float sin = 0.5f + 0.5f * Mathf.Sin(Time.time * frequency);
|
|
graphic.color = gradient.Evaluate(sin);
|
|
}
|
|
|
|
private bool GameModeAvailable()
|
|
{
|
|
if (SettingsManager.GetBool("Freeplay", false)) return true;
|
|
return SingleWallet.Balance >= PlayerPrefs.GetInt(PriceKey, 10);
|
|
}
|
|
private void RefreshState(int a = 0) => RefreshState();
|
|
private void RefreshState()
|
|
{
|
|
readyToBlink = GameModeAvailable();
|
|
if (!readyToBlink)
|
|
graphic.color = Vector4.zero;
|
|
}
|
|
}
|