Добавить таймеры и шкалы прогресса, расширить призовую систему и контроль остатков, восстановить настройки и обновить таблицу призов главного меню.
110 lines
2.6 KiB
C#
110 lines
2.6 KiB
C#
using PrizeSystem;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class QrPanel : MonoBehaviour, IControlable
|
|
{
|
|
public event Action OnComplete;
|
|
|
|
[SerializeField] private Image QrImage;
|
|
[SerializeField] private TextMeshProUGUI Label;
|
|
[SerializeField] private float _timeout = 300f;
|
|
|
|
private Sprite _generatedSprite;
|
|
private Texture2D _generatedTexture;
|
|
private float _closeAt;
|
|
private bool _initialized;
|
|
private bool _waitForActionRelease;
|
|
|
|
public bool ControlsEnabled { get; set; }
|
|
|
|
private void Update()
|
|
{
|
|
if (_initialized && Time.unscaledTime >= _closeAt)
|
|
Close();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
ControlsEnabled = false;
|
|
_initialized = false;
|
|
Clear();
|
|
}
|
|
|
|
public void Initialize(Prize prize)
|
|
{
|
|
if (_initialized)
|
|
return;
|
|
|
|
if (prize is not QrPrize qrPrize)
|
|
{
|
|
OnComplete?.Invoke();
|
|
return;
|
|
}
|
|
|
|
Clear();
|
|
_generatedTexture = QrMaker.MakePrizeTexture(qrPrize);
|
|
_generatedTexture.filterMode = FilterMode.Point;
|
|
_generatedSprite = Sprite.Create(
|
|
_generatedTexture,
|
|
new Rect(0, 0, _generatedTexture.width, _generatedTexture.height),
|
|
new Vector2(0.5f, 0.5f));
|
|
QrImage.sprite = _generatedSprite;
|
|
QrImage.preserveAspect = true;
|
|
Label.text = qrPrize.PrizeText;
|
|
|
|
PrizeSystemManager.ReportPrizeIssued();
|
|
_closeAt = Time.unscaledTime + _timeout;
|
|
_waitForActionRelease = true;
|
|
_initialized = true;
|
|
ControlsEnabled = true;
|
|
ControlsPerformer.Instance.SetControlable(this);
|
|
}
|
|
|
|
public void UpdateControls()
|
|
{
|
|
if (!_initialized)
|
|
return;
|
|
|
|
if (_waitForActionRelease)
|
|
{
|
|
if (In.GetAction(JoystickSide.Both, InteractMode.Continious))
|
|
return;
|
|
|
|
_waitForActionRelease = false;
|
|
}
|
|
|
|
if (In.GetAction(JoystickSide.Both, InteractMode.Discrete))
|
|
Close();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
if (!_initialized)
|
|
return;
|
|
|
|
_initialized = false;
|
|
ControlsEnabled = false;
|
|
ControlsPerformer.Instance.SetControlable(null);
|
|
gameObject.SetActive(false);
|
|
OnComplete?.Invoke();
|
|
}
|
|
|
|
private void Clear()
|
|
{
|
|
if (QrImage != null)
|
|
QrImage.sprite = null;
|
|
|
|
if (_generatedSprite != null)
|
|
Destroy(_generatedSprite);
|
|
|
|
if (_generatedTexture != null)
|
|
Destroy(_generatedTexture);
|
|
|
|
_generatedSprite = null;
|
|
_generatedTexture = null;
|
|
}
|
|
}
|