using System; using System.Collections.Generic; using Code.Infrastructure.EventBus; using Code.Infrastructure.UI; using Reflex.Attributes; using TMPro; using UnityEngine; namespace Code.Example.Race.UI { public class PlayerScoreCounter : UIPanel, IScoreChangedHandle { [SerializeField] private TMP_Text playerScore; private EventBus _eventBus; [Inject] private void Construct(EventBus eventBus) { _eventBus = eventBus; _eventBus.Subscribe(this); } public override void Open(Action callback = null) { playerScore.gameObject.SetActive(true); callback?.Invoke(); // image.DOColor(shownColor, 1f).onComplete = () => callback?.Invoke(); } public override void Close(Action callback = null) { playerScore.gameObject.SetActive(false); callback?.Invoke(); // image.DOColor(hiddenColor, 1f).onComplete += () => callback?.Invoke(); } public void ScoreChanged(Racer.Racer racer, ScoreData additionalScore, List> scores) { // if (racer.Data.type == RacerType.Player) string output = ""; foreach (var score in scores) output += $@"{score.Key.Data.name}: {score.Value.lapsPassed} \t {score.Value.checkpointsPassed}\n"; playerScore.text = output; } } }