46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Code.GameplayServices;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Code.UI
|
|
{
|
|
public class ScoreTable : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform scoreDataBox;
|
|
[SerializeField] private ScoreDataView scoreDataPrefab;
|
|
[SerializeField] private Button exitButton;
|
|
private List<ScoreDataView> _scoreDataViews = new();
|
|
|
|
private void Awake()
|
|
{
|
|
exitButton.onClick.AddListener(HideTable);
|
|
HideTable();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
exitButton.onClick.RemoveListener(HideTable);
|
|
}
|
|
|
|
private void HideTable() => gameObject.SetActive(false);
|
|
private void OnEnable()
|
|
{
|
|
foreach (var score in PlayerScoreService.Instance.Scores)
|
|
{
|
|
var scoreData = Instantiate(scoreDataPrefab, scoreDataBox);
|
|
scoreData.SetScoreData(score);
|
|
_scoreDataViews.Add(scoreData);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
foreach (var scoreDataView in _scoreDataViews)
|
|
{
|
|
Destroy(scoreDataView.gameObject);
|
|
}
|
|
_scoreDataViews.Clear();
|
|
}
|
|
}
|
|
} |