57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using RR.Game2D.Core.Managers;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class QRCodeUIController : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform content;
|
|
|
|
private PrizeSystemManager _prizeSystemManager;
|
|
private GameObject[] _qrCodes;
|
|
|
|
private void Start()
|
|
{
|
|
_prizeSystemManager = PrizeSystemManager.Instance;
|
|
|
|
GameManager.Instance.GameWonEvent += AddQRCodes;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
GameManager.Instance.GameWonEvent -= AddQRCodes;
|
|
}
|
|
|
|
private void AddQRCodes(float _)
|
|
{
|
|
if (_qrCodes != null) ClearQRCodes();
|
|
|
|
Texture2D[] qrCodesImages = _prizeSystemManager.GetQRCodes();
|
|
_qrCodes = new GameObject[qrCodesImages.Length];
|
|
|
|
for (int i = 0; i < qrCodesImages.Length; i++)
|
|
{
|
|
_qrCodes[i] = new GameObject("QRCode_" + i, typeof(RectTransform), typeof(Image));
|
|
_qrCodes[i].transform.SetParent(content, false);
|
|
|
|
Sprite sprite = Sprite.Create(qrCodesImages[i],
|
|
new Rect(0, 0, qrCodesImages[i].width,
|
|
qrCodesImages[i].height),
|
|
new Vector2(0.5f, 0.5f));
|
|
|
|
_qrCodes[i].GetComponent<Image>().sprite = sprite;
|
|
}
|
|
}
|
|
|
|
private void ClearQRCodes()
|
|
{
|
|
if (_qrCodes == null) return;
|
|
|
|
foreach (GameObject qrCode in _qrCodes)
|
|
{
|
|
Destroy(qrCode);
|
|
}
|
|
|
|
_qrCodes = null;
|
|
}
|
|
}
|