Skip to content

180 Degree rotation does not trigger OnRectTransformDimensionsChange() #44

@5argon

Description

@5argon

The rect need to recalculate using a new Screen.safeArea and Screen.cutouts when rotation changed. Contrary to 90 degree rotation which will be very rare, it is much more common for a game to allow 180 degree orientation change. (e.g. allow the player to avoid hand occluding speaker while playing, depending on phones)

But I just found that "dimension" of the rect didn't change in 180 degree case so this OnRectTransformDimensionsChange() do not get called. And therefore we have nothing to catch this event. Unity didn't expose any event that could catch this. Despite what the internet says. (Tested on Android, 2019.3, S10+)

  • Check device orientation in Update repeatedly and monitor orientation : wasteful, not instantaneous, and unprofessional.
  • Ask the developer to lock the orientation and use code to rotate manually in response to gyro or some buttons in the game, then call a specially prepared method to refresh all rects : weird
  • Make a magic rect beacon that guarantees changing its dimension on every rotation (how?), and then we maybe able to keep using OnRectTransformDimensionsChange() and relay rebuild information to all rects : I think this is impossible as the Canvas could only response to Screen size, and on 180 rotation the screen size will not change by definition. The canvas should not even redraw in this case and therefore no such magic responsive rect can exist under it. (?)
  • Write a native plugin for Android and iOS to catch native event : painful but likely the only proper solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions