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.
35 lines
876 B
35 lines
876 B
using UnityEngine;
|
|
|
|
public class FullScreen : MonoBehaviour
|
|
{
|
|
[SerializeField] Vector2 adding = new Vector2(0, 0);
|
|
|
|
Vector2 prevScreenSize = Vector2.zero;
|
|
|
|
private void Awake()
|
|
{
|
|
Apply();
|
|
prevScreenSize = new Vector2(Screen.width, Screen.height);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
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;
|
|
|
|
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(Screen.width + adding.x, Screen.height + adding.y);
|
|
}
|
|
}
|