Skip to content

Commit

Permalink
Replaced retries by a delay
Browse files Browse the repository at this point in the history
  • Loading branch information
fcolarich committed Dec 20, 2024
1 parent 02d496d commit 90827b0
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public partial class UICanvasInformationSystem : BaseUnityLoopSystem
private BorderRect interactableArea;
private int lastViewportResolutionWidth = -1;
private int lastScreenRealResolutionWidth = -1;
private const int TOTAL_ATTEMPTS = 3;
private int currentAttempts = 0;
private const int TOTAL_DELAY = 3;
private int delay = 0;

public override void Initialize()
{
Expand All @@ -38,7 +38,7 @@ private UICanvasInformationSystem(World world, ISceneStateProvider sceneStatePro
{
this.sceneStateProvider = sceneStateProvider;
this.ecsToCRDTWriter = ecsToCRDTWriter;
currentAttempts = 0;
delay = 0;
}

protected override void Update(float t)
Expand All @@ -55,13 +55,15 @@ private void PropagateToScene()

private void UpdateUICanvasInformationComponent()
{
if (lastViewportResolutionWidth == Screen.width && lastScreenRealResolutionWidth == Screen.mainWindowDisplayInfo.width)
//We add this logic because in the first frames the message gets lost and we wont send the size of the canvas
//to the scene, causing breaking UIs, so we delay this.
if (delay < TOTAL_DELAY)
{
//We add this logic because in the first frames the message might get lost and we wont send correctly the size of the screen
//to the scene, causing breaking UIs
if (currentAttempts > TOTAL_ATTEMPTS) { return; }
currentAttempts++;
delay++;
return;
}

if (lastViewportResolutionWidth == Screen.width && lastScreenRealResolutionWidth == Screen.mainWindowDisplayInfo.width) return;

lastScreenRealResolutionWidth = Screen.mainWindowDisplayInfo.width;
lastViewportResolutionWidth = Screen.width;
Expand Down

0 comments on commit 90827b0

Please sign in to comment.