fix: Network Problems on Ball Synchronization

This commit is contained in:
Syntriax 2024-02-05 12:44:29 +03:00
parent 70ac012a83
commit edd2dd8511
2 changed files with 6 additions and 4 deletions

View File

@ -14,6 +14,7 @@ public class PongManagerBehaviour : BehaviourOverride
{ {
public Action<PongManagerBehaviour>? OnReset { get; set; } = null; public Action<PongManagerBehaviour>? OnReset { get; set; } = null;
public Action<PongManagerBehaviour>? OnFinished { get; set; } = null; public Action<PongManagerBehaviour>? OnFinished { get; set; } = null;
public Action<PongManagerBehaviour>? OnScoresUpdated { get; set; } = null;
public Action<PongManagerBehaviour>? OnScored { get; set; } = null; public Action<PongManagerBehaviour>? OnScored { get; set; } = null;
private INetworkCommunicator communicator = null!; private INetworkCommunicator communicator = null!;
@ -47,7 +48,7 @@ public class PongManagerBehaviour : BehaviourOverride
{ {
ScoreLeft = reader.GetInt(); ScoreLeft = reader.GetInt();
ScoreRight = reader.GetInt(); ScoreRight = reader.GetInt();
OnScored?.Invoke(this); OnScoresUpdated?.Invoke(this);
CheckFinish(); CheckFinish();
} }
@ -55,6 +56,7 @@ public class PongManagerBehaviour : BehaviourOverride
public void ScoreToLeft() public void ScoreToLeft()
{ {
ScoreLeft++; ScoreLeft++;
OnScoresUpdated?.Invoke(this);
OnScored?.Invoke(this); OnScored?.Invoke(this);
SendData(); SendData();
@ -65,6 +67,7 @@ public class PongManagerBehaviour : BehaviourOverride
public void ScoreToRight() public void ScoreToRight()
{ {
ScoreRight++; ScoreRight++;
OnScoresUpdated?.Invoke(this);
OnScored?.Invoke(this); OnScored?.Invoke(this);
SendData(); SendData();
@ -75,6 +78,7 @@ public class PongManagerBehaviour : BehaviourOverride
public void Reset() public void Reset()
{ {
ScoreLeft = ScoreRight = 0; ScoreLeft = ScoreRight = 0;
OnScoresUpdated?.Invoke(this);
OnReset?.Invoke(this); OnReset?.Invoke(this);
SendData(); SendData();

View File

@ -14,9 +14,7 @@ public class TextScoreBehaviour : TextBehaviour
if (!GameObject.GameManager.TryFindBehaviour(out pongManager)) if (!GameObject.GameManager.TryFindBehaviour(out pongManager))
return; return;
pongManager.OnFinished += UpdateScores; pongManager.OnScoresUpdated += UpdateScores;
pongManager.OnScored += UpdateScores;
pongManager.OnReset += UpdateScores;
UpdateScores(pongManager); UpdateScores(pongManager);
} }