Unity_Web/Assets/1_Script/ScreenMove.cs

60 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScreenMove : MonoBehaviour
{
[SerializeField] RectTransform rectTransform;
[SerializeField] RectTransform test_rectTransform;
readonly Vector2 stretch = new Vector2(0f, 0.5f);
readonly Vector2 middle = new Vector2(1f, 0.5f);
readonly Vector2 center = new Vector2(0.5f, 0.5f);
readonly Vector2 movePos = new Vector2(-58.5f, 20f);
readonly Vector2 moveSize = new Vector2(-343f, 100f);
readonly Vector2 idlePos = new Vector2(-58.5f, 20f);
readonly Vector2 idleSize = new Vector2(553f, 100f);
bool isMobile;
void Awake()
{
isMobile = Application.isMobilePlatform;
}
private void Start()
{
//모바일은 한번만 업데이트
if (isMobile)
{
rectTransform.sizeDelta = new Vector2(Screen.width, Screen.height);
}
}
private void Update()
{
//pc는 실시간 업데이트
if (!isMobile)
{
rectTransform.sizeDelta = new Vector2(Screen.width, Screen.height);
//1280
//Debug.Log($"{Screen.width} : {Screen.height}");
if (Screen.width < 1280)
{
test_rectTransform.anchorMin = center;
test_rectTransform.anchorMax = center;
test_rectTransform.anchoredPosition = idlePos;
test_rectTransform.sizeDelta = idleSize;
}
else
{
test_rectTransform.anchorMin = stretch;
test_rectTransform.anchorMax = middle;
test_rectTransform.anchoredPosition = movePos;
test_rectTransform.sizeDelta = moveSize;
}
//Debug.Log($"{test_rectTransform.anchoredPosition} : {test_rectTransform.sizeDelta}");
}
}
}