Files
Infratest/Assets/Code/Example/Race/UI/PlayerScoreCounter.cs
T

49 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using Code.Example.Race.Racer;
using Code.Example.Race.Track;
using Code.Infrastructure.EventBus;
using Code.Infrastructure.UI;
using Reflex.Attributes;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
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);
// image.DOColor(shownColor, 1f).onComplete = () => callback?.Invoke();
}
public override void Close(Action callback = null)
{
playerScore.gameObject.SetActive(true);
// image.DOColor(hiddenColor, 1f).onComplete += () => callback?.Invoke();
}
public void OnRacerPassedCheckpoint(Racer.Racer racer)
{
}
public void ScoreChanged(Racer.Racer racer, int additionalScore, List<KeyValuePair<Racer.Racer,int>> scores)
{
// if (racer.Data.type == RacerType.Player)
string output = "";
foreach (var score in scores) output += $@"{score.Key.Data.name}: {score.Value}\n";
playerScore.text = output;
}
}
}