Контроль музыки, пробел
This commit is contained in:
1 parent
a45223d0e7
commit
cd56b1969c
12 files changed
+344
-95
No files matched your search
@@ -65,7 +65,7 @@ namespace Code.Example.Race
|
||||
_raceTrackData.trackData.RacerPoints[i].transform).GetComponent<Racer.AI.Racer>());
|
||||
PlacedRacers[^1].SetData(_racerPrefabs[_randomizedTypes[i]].Data);
|
||||
PlacedRacers[^1].Id = i;
|
||||
_scores.SubscribeRacer(i);
|
||||
_scores.SubscribeRacer(PlacedRacers[^1]);
|
||||
}
|
||||
|
||||
foreach (var racer in PlacedRacers)
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Code.Example.Race
|
||||
{
|
||||
public class RaceScores : IRacerPassedCheckpointHandler, IDisposable
|
||||
{
|
||||
private Dictionary<int, int> _scores = new();
|
||||
private Dictionary<Racer.AI.Racer, int> _scores = new();
|
||||
private EventBus _eventBus;
|
||||
|
||||
public RaceScores(EventBus eventBus)
|
||||
@@ -16,28 +16,28 @@ namespace Code.Example.Race
|
||||
_eventBus = eventBus;
|
||||
_eventBus.Subscribe(this);
|
||||
}
|
||||
public void SubscribeRacer(int racer)
|
||||
public void SubscribeRacer(Racer.AI.Racer racer)
|
||||
{
|
||||
_scores.Add(racer, 0);
|
||||
}
|
||||
|
||||
public void ChangeScore(int racer, int additionalScore)
|
||||
public void ChangeScore(Racer.AI.Racer racer, int additionalScore)
|
||||
{
|
||||
_scores[racer] += additionalScore;
|
||||
_eventBus.RaiseEvent<IScoreChangedHandle>(x=> x.ScoreChanged(racer,additionalScore, GetScores()));
|
||||
}
|
||||
|
||||
public void UnsubscribeRacer(int racer)
|
||||
public void UnsubscribeRacer(Racer.AI.Racer racer)
|
||||
{
|
||||
_scores.Remove(racer);
|
||||
}
|
||||
|
||||
public List<KeyValuePair<int, int>> GetScores()
|
||||
public List<KeyValuePair<Racer.AI.Racer, int>> GetScores()
|
||||
{
|
||||
return _scores.OrderByDescending(x => x.Value).ToList();
|
||||
}
|
||||
|
||||
public void OnRacerPassedCheckpoint(Racer.AI.Racer racer) => ChangeScore(racer.Id,1);
|
||||
public void OnRacerPassedCheckpoint(Racer.AI.Racer racer) => ChangeScore(racer,1);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -47,6 +47,6 @@ namespace Code.Example.Race
|
||||
|
||||
public interface IScoreChangedHandle : IGlobalSubscriber
|
||||
{
|
||||
void ScoreChanged(int racer, int additionalScore, List<KeyValuePair<int, int>> scores);
|
||||
void ScoreChanged(Racer.AI.Racer racer, int additionalScore, List<KeyValuePair<Racer.AI.Racer, int>> scores);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace Code.Example.Race.Racer.Player
|
||||
|
||||
private void MovementEnded(InputAction.CallbackContext context) => MovementInput = Vector2.zero;
|
||||
|
||||
private void BrakePerformed(InputAction.CallbackContext context) => Brake = context.ReadValue<bool>();
|
||||
private void BrakePerformed(InputAction.CallbackContext context) => Brake = true;
|
||||
|
||||
private void BrakeEnded(InputAction.CallbackContext context) => Brake = false;
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ namespace Code.Example.Race.UI
|
||||
{
|
||||
}
|
||||
|
||||
public void ScoreChanged(int racer, int additionalScore, List<KeyValuePair<int,int>> scores)
|
||||
public void ScoreChanged(Racer.AI.Racer racer, int additionalScore, List<KeyValuePair<Racer.AI.Racer,int>> scores)
|
||||
{
|
||||
// if (racer.Data.type == RacerType.Player)
|
||||
string output = "";
|
||||
foreach (var score in scores) output += $@"{score.Key}: {score.Value}\n";
|
||||
foreach (var score in scores) output += $@"{score.Key.Data.name}: {score.Value}\n";
|
||||
playerScore.text = output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user