quetty

← Back

Infinite Geometry - UI Safezone

February 05, 2020

Upgrading a project from 2014 made with Unity 4.6

Infinite Geometry was a game I made in 2014 with Unity 4.6. It was a little game, but i think the core concept of it is quite unique and not like anythink else. I took it down because I didn’t want to pay for another Apple Developer Programm.


One thing that needed an update, was the support of phone notches (like the iPhone X).

Example of phone notch

This was a simple task. I just added a safe zone UI GameObject. I used the following code to always scale the object to safe zone size and every UI elememt is a child of this object.

void ApplySafeArea()
{
    Rect r = Screen.safeArea;

    // Convert safe area rectangle from absolute pixels to normalised anchor coordinates
    Vector2 anchorMin = r.position;
    Vector2 anchorMax = r.position + r.size;
    anchorMin.x /= Screen.width;
    anchorMin.y /= Screen.height;
    anchorMax.x /= Screen.width;
    anchorMax.y /= Screen.height;
    rectTransform.anchorMin = anchorMin;
    rectTransform.anchorMax = anchorMax;
}