Skip to content

Commit

Permalink
Fixed UI not updating correctly using PBUiCanvasInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
fcolarich committed Dec 20, 2024
1 parent fa63ac6 commit 02d496d
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +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;

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

protected override void Update(float t)
Expand All @@ -53,12 +56,17 @@ private void PropagateToScene()
private void UpdateUICanvasInformationComponent()
{
if (lastViewportResolutionWidth == Screen.width && lastScreenRealResolutionWidth == Screen.mainWindowDisplayInfo.width)
return;
{
//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++;
}

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

ecsToCRDTWriter.PutMessage<PBUiCanvasInformation, UICanvasInformationSystem>(static (component, system) =>
ecsToCRDTWriter.PutMessage<PBUiCanvasInformation, UICanvasInformationSystem>((component, system) =>
{
component.InteractableArea = system.interactableArea;
component.Width = Screen.width;
Expand Down

0 comments on commit 02d496d

Please sign in to comment.