chip-gameV3/Assets/PrizesSelector.cs

51 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CharacterSystem;
using PrizeSystem;
using UnityEngine;
public class PrizesSelector : MonoBehaviour
{
[SerializeField] RectTransform _addedPrizesTable;
[SerializeField] PrizeView _prizeViewPrefab;
[SerializeField] AvailablePrizesTable _availablePrizesTable;
private PrizeSet set;
public void Open(Character character)
{
print($"открыто с персонажем {character.CharacterIndex}");
gameObject.SetActive(true);
set = PrizeSystemManager.PrizeContainer.Sets[character.CharacterIndex];
UpdateView();
}
private void UpdateView()
{
ClearTable();
DisplayPrizeSet(set);
_availablePrizesTable.Refresh(set);
}
private void ClearTable()
{
for (int i = _addedPrizesTable.childCount - 1; i >= 0; i--)
{
var go = _addedPrizesTable.GetChild(i).gameObject;
Destroy(go);
}
}
private void DisplayPrizeSet(PrizeSet prizeSet)
{
foreach (var item in prizeSet.Prizes)
{
var view = Instantiate(_prizeViewPrefab, _addedPrizesTable);
view.SetPrize(item);
}
}
}