39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
using UnityEngine;
|
||
|
||
public class ScoreSynchronizer : MonoBehaviour
|
||
{
|
||
[SerializeField] private bool IsPlayer = true;
|
||
|
||
private TMPro.TextMeshProUGUI tmp;
|
||
|
||
private void Awake()
|
||
{
|
||
tmp = this.GetComponent<TMPro.TextMeshProUGUI>();
|
||
|
||
if (GameManager.Instance != null)
|
||
{
|
||
GameManager.Event.RegistEvent(EEventType.OnInitializeGame, this.OnInitializeGame);
|
||
GameManager.Event.RegistEvent(EEventType.OnSynchronizeScore, this.OnSynchronizeScore);
|
||
}
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
if (GameManager.Instance != null)
|
||
{
|
||
GameManager.Event.RemoveEvent(EEventType.OnInitializeGame, this.OnInitializeGame);
|
||
GameManager.Event.RemoveEvent(EEventType.OnSynchronizeScore, this.OnSynchronizeScore);
|
||
}
|
||
}
|
||
|
||
private void OnInitializeGame()
|
||
{
|
||
tmp.text = "0 <20><>";
|
||
}
|
||
|
||
private void OnSynchronizeScore()
|
||
{
|
||
tmp.text = GamePanel.Instance.GetTotalScore(IsPlayer, false).ToString() + " <20><>";
|
||
}
|
||
}
|