The "Always fit on screen" does not work when the force aspect ratio option is enabled in case of pillarbox borders. I have a Unity UI hotspot menu (canvas + panel). The behaviour is correct when no sideborders are on screen: if the label is too big, the position is correctly clamped in the screen area. However, if 21:9 mode is enabled, the label crosses the game area and becomes partially invisible. The engine is not considering the pillarbox border!
The canvas render mode is Screen Space / Overlay.
I am showing the bug here: the upper one is 16:9 (correct behaviour), the lower one is 21:9 (label cut)
my menu settings
Maybe a script like this should work (placed on the panel / child of the canvas)?
public void forcePosition(){
Rect screenRect = AC.KickStarter.mainCamera.LimitMenuToAspect(new Rect(0, 0, Screen.width, Screen.height));
Vector2 screenSizeDelta = new Vector2(screenRect.size.x,screenRect.size.y);
float maxX = parentCanvas.scaleFactor*((screenSizeDelta.x / 2)-selfPanel.sizeDelta.x/2.0f);
float minX = -maxX;
selfPanel.localPosition = new Vector2 (
Mathf.Clamp(
selfPanel.localPosition.x,minX,maxX
),
selfPanel.localPosition.y
);
}
Comments