Skip to content

Instantly share code, notes, and snippets.

@dyguests
Last active June 20, 2023 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyguests/b357ff8cadbbf8df1a5fc2228c9c80c5 to your computer and use it in GitHub Desktop.
Save dyguests/b357ff8cadbbf8df1a5fc2228c9c80c5 to your computer and use it in GitHub Desktop.
SizePerfectCanvas. adapter size.
using UnityEngine;
using UnityEngine.UI;
namespace Script.Tools
{
[RequireComponent(typeof(CanvasScaler))]
[ExecuteAlways]
public class SizePerfectCanvas : MonoBehaviour
{
[SerializeField] private CanvasScaler canvasScaler;
private void OnRectTransformDimensionsChange()
{
canvasScaler.matchWidthOrHeight = Screen.width * canvasScaler.referenceResolution.y < canvasScaler.referenceResolution.x * Screen.height ? 0f : 1f;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment