You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1020 B
38 lines
1020 B
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FullScreen : MonoBehaviour
|
|
{
|
|
[SerializeField] CanvasScaler canvasScaler;
|
|
[SerializeField] Vector2 adding = new Vector2(0, 0);
|
|
|
|
Vector2 prevScreenSize = Vector2.zero;
|
|
|
|
private void OnEnable()
|
|
{
|
|
Apply();
|
|
prevScreenSize = new Vector2(Screen.width, Screen.height);
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (prevScreenSize.x != Screen.width || prevScreenSize.y != Screen.height)
|
|
{
|
|
Apply();
|
|
prevScreenSize = new Vector2(Screen.width, Screen.height);
|
|
}
|
|
}
|
|
|
|
private void Apply()
|
|
{
|
|
var rt = transform as RectTransform;
|
|
var csRt = canvasScaler.transform as RectTransform;
|
|
|
|
rt.pivot = new Vector2(0.5f, 0.5f);
|
|
rt.anchorMin = new Vector2(0.5f, 0.5f);
|
|
rt.anchorMax = new Vector2(0.5f, 0.5f);
|
|
|
|
rt.anchoredPosition = Vector2.zero;
|
|
rt.sizeDelta = new Vector2(csRt.sizeDelta.x + adding.x, csRt.sizeDelta.y + adding.y);
|
|
}
|
|
}
|