50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
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();
|
|
PaymentSystem.onCoinAdded += RefreshState;
|
|
PaymentSystem.onCoinRemoved += RefreshState;
|
|
SettingsManager.OnSettingsChanged.AddListener(RefreshState);
|
|
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
PaymentSystem.onCoinAdded -= RefreshState;
|
|
PaymentSystem.onCoinRemoved -= 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 PaymentSystem.Balance >= PlayerPrefs.GetInt(PriceKey, 10);
|
|
}
|
|
private void RefreshState(int a = 0) => RefreshState();
|
|
private void RefreshState()
|
|
{
|
|
readyToBlink = GameModeAvailable();
|
|
if (!readyToBlink)
|
|
graphic.color = Vector4.zero;
|
|
}
|
|
} |