rabidus-test/Assets/MonumentResultController.cs

78 lines
2.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class MonumentResultController : MonoBehaviour
{
private List<MonumentInfo> _monuments;
[SerializeField]
private UIMonumentButton _UIMonumentPrefab;
[SerializeField]
private Transform _placeHolder;
[SerializeField]
private Transform _miniPlaceholder;
[SerializeField]
private TMPro.TextMeshProUGUI _descriptionText;
[SerializeField]
private TMPro.TextMeshProUGUI _score;
[SerializeField]
private Image _icon;
private Dictionary<MonumentInfo,GameObject> _miniModels = new Dictionary<MonumentInfo, GameObject>();
private GameObject _lastMiniModel;
private void Start()
{
_monuments = new List<MonumentInfo>();
_monuments = Resources.LoadAll<MonumentInfo>("Monuments/").ToList();
InitMonuments();
}
private bool _showFirst = true;
private void InitMonuments()
{
_monuments.ForEach(x =>
{
var newUIMonument = Instantiate(_UIMonumentPrefab, _placeHolder);
newUIMonument.Init(x);
var newMiniModel = Instantiate(x.MiniModel, _miniPlaceholder);
newMiniModel.SetActive(false);
_miniModels.Add(x, newMiniModel);
if (PlayerSetup.Instance.TryFindMonument(x))
{
newUIMonument.Unlock();
if (_showFirst)
{
_showFirst = false;
newUIMonument.SelectMonument();
}
}
else
{
newUIMonument.Lock();
}
});
}
public void SelectMonument(MonumentInfo info)
{
if (_lastMiniModel)
_lastMiniModel.SetActive(false);
_miniModels[info].SetActive(true);
_lastMiniModel = _miniModels[info];
_icon.sprite = info.Image;
_descriptionText.SetText(info.Description);
}
}