38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using PrizeSystem;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class SpecialPrizeView : MonoBehaviour
|
|
{
|
|
[SerializeField] CanvasGroup canvasGroup;
|
|
[SerializeField] private TextMeshProUGUI PrizeText;
|
|
|
|
public void Init()
|
|
{
|
|
Refresh(PrizeSystemManager.cachedPrizes);
|
|
PrizeSystemManager.PrizesChanged += Refresh;
|
|
}
|
|
|
|
private void OnDestroy() => PrizeSystemManager.PrizesChanged -= Refresh;
|
|
|
|
private void Refresh(List<Prize> prizes)
|
|
{
|
|
var qrPrizes = prizes.OfType<QrPrize>().ToList();
|
|
|
|
bool prizing = SettingsManager.GetBool(SettingKeys.PRIZING, false);
|
|
bool hasQrPrizes = qrPrizes.Count > 0;
|
|
bool needToDisplay = prizing && hasQrPrizes;
|
|
|
|
if (needToDisplay) PrizeText.text = GetMostRankedPrize(qrPrizes).PrizeText;
|
|
canvasGroup.alpha = needToDisplay ? 1 : 0;
|
|
}
|
|
|
|
private QrPrize GetMostRankedPrize(List<QrPrize> qrPrizes) //это можно в призовую систему перегнать или в утильку
|
|
{
|
|
if (qrPrizes == null || qrPrizes.Count == 0)
|
|
return null;
|
|
return qrPrizes.OrderByDescending(p => p.Rank).FirstOrDefault();
|
|
}
|
|
} |