rabidus-test/Assets/MonumentResultController.cs

68 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class MonumentResultController : MonoBehaviour, IPlayerInfoRequre
{
private List<MonumentInfo> _monuments;
[SerializeField]
private UIMonumentButton _UIMonumentPrefab;
[SerializeField]
private Transform _placeHolder;
[SerializeField]
private TMPro.TextMeshProUGUI _descriptionText;
[SerializeField]
private Image _icon;
[SerializeField]
private TMPro.TextMeshProUGUI _score;
private PlayerSetup _playerSetup;
private void Start()
{
_monuments = new List<MonumentInfo>();
_monuments = Resources.LoadAll<MonumentInfo>("Monuments/").ToList();
InitPlayerInfo();
InitMonuments();
}
public void InitPlayerInfo()
{
_playerSetup = FindObjectOfType<PlayerSetup>();
}
private bool _showFirst = true;
private void InitMonuments()
{
_monuments.ForEach(x =>
{
var newUIMonument = Instantiate(_UIMonumentPrefab, _placeHolder);
newUIMonument.Init(x);
if (_playerSetup.TryFindMonument(x))
{
newUIMonument.Unlock();
if (_showFirst)
{
_showFirst = false;
newUIMonument.SelectMonument();
}
}
});
}
public void SelectMonument(MonumentInfo info)
{
_icon.sprite = info.Image;
_score.SetText(info.Score.ToString());
_descriptionText.SetText(info.Description);
}
}