Добавить таймеры и шкалы прогресса, расширить призовую систему и контроль остатков, восстановить настройки и обновить таблицу призов главного меню.
125 lines
3.4 KiB
C#
125 lines
3.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class VitrinaCatcher : MonoBehaviour
|
|
{
|
|
public event Action<bool> ResultClosed;
|
|
|
|
[Header("Ссылки")]
|
|
[SerializeField] private RectTransform Panel;
|
|
[SerializeField] private CanvasGroup MainCanvasGroup;
|
|
[SerializeField] private CanvasGroup SuccessCanvasGroup;
|
|
[SerializeField] private CanvasGroup ErrorCanvasGroup;
|
|
|
|
[SerializeField] private TextMeshProUGUI DateLabel;
|
|
[SerializeField] private TextMeshProUGUI TimeToCloseLabel;
|
|
|
|
[Header("Настройки анимации")]
|
|
[SerializeField] private float MinY = -200;
|
|
[SerializeField] private float MaxY = 0;
|
|
[SerializeField] private float AppearTime = 0.5f;
|
|
|
|
[SerializeField] private float DisappearTimeSuccess = 5;
|
|
[SerializeField] private float DisappearTimeError = 60;
|
|
|
|
private bool animating = false;
|
|
private bool _currentSuccess;
|
|
|
|
public static VitrinaCatcher Instance { get; private set; }
|
|
public void Initialize()
|
|
{
|
|
Instance = this;
|
|
PrizeStandController.OpeningFinished -= DisplayOpenResult;
|
|
PrizeStandController.OpeningFinished += DisplayOpenResult;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
PrizeStandController.OpeningFinished -= DisplayOpenResult;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (animating && In.GetAxis(JoystickSide.Both, InteractMode.Discrete).x > 0)
|
|
{
|
|
StopAllCoroutines();
|
|
Hide();
|
|
}
|
|
}
|
|
|
|
private void Hide()
|
|
{
|
|
MainCanvasGroup.alpha = 0;
|
|
SuccessCanvasGroup.gameObject.SetActive(false);
|
|
ErrorCanvasGroup.gameObject.SetActive(false);
|
|
animating = false;
|
|
gameObject.SetActive(false);
|
|
ResultClosed?.Invoke(_currentSuccess);
|
|
}
|
|
|
|
|
|
public void DisplayOpenResult(bool success, string message)
|
|
{
|
|
if (success)
|
|
PrizeSystem.PrizeSystemManager.ReportPrizeIssued();
|
|
|
|
_currentSuccess = success;
|
|
gameObject.SetActive(true);
|
|
InitializeBySuccess(success);
|
|
}
|
|
|
|
private void InitializeBySuccess(bool success)
|
|
{
|
|
MainCanvasGroup.alpha = 0;
|
|
SuccessCanvasGroup.alpha = 0;
|
|
ErrorCanvasGroup.alpha = 0;
|
|
|
|
SuccessCanvasGroup.gameObject.SetActive(success);
|
|
ErrorCanvasGroup.gameObject.SetActive(!success);
|
|
|
|
if(!success)
|
|
DateLabel.text = DateTime.Now.ToString("G");
|
|
|
|
StartCoroutine(Show(success));
|
|
}
|
|
|
|
private IEnumerator Show(bool success)
|
|
{
|
|
animating = true;
|
|
float t = 0;
|
|
float startTime = Time.time;
|
|
|
|
while (t < 1)
|
|
{
|
|
float elapsed = Time.time - startTime;
|
|
t = elapsed / AppearTime;
|
|
|
|
Panel.position = new Vector2(0, Mathf.Lerp(MinY, MaxY, t));
|
|
MainCanvasGroup.alpha = t;
|
|
yield return null;
|
|
}
|
|
|
|
CanvasGroup cg = success ? SuccessCanvasGroup : ErrorCanvasGroup;
|
|
startTime = Time.time;
|
|
while (Time.time < startTime + AppearTime)
|
|
{
|
|
float elapsed = Time.time - startTime;
|
|
cg.alpha = elapsed/AppearTime;
|
|
yield return null;
|
|
}
|
|
|
|
float disappearTime = success ? DisappearTimeSuccess : DisappearTimeError;
|
|
|
|
for(int i = (int)disappearTime; i >= 0; i--)
|
|
{
|
|
TimeToCloseLabel.text = i.ToString();
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
|
|
|
|
Hide();
|
|
}
|
|
}
|