using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// /// public class UIBgAdaptive : MonoBehaviour { public GameObject[] bgList; void Start() { for (int i = 0; i < bgList.Length; i++) { if (bgList[i] != null) { bgList[i].GetComponent().anchorMin = new Vector2(0.5f, 0.5f); bgList[i].GetComponent().anchorMax = new Vector2(0.5f, 0.5f); bgList[i].GetComponent().pivot = new Vector2(0.5f, 0.5f); bgList[i].transform.localScale = new Vector3(1, 1, 1); bgList[i].transform.localPosition = new Vector3(0, 0, 0); //float curHeight = 1920 * (Screen.height / Screen.width) / (1920 / 1080); //float curWidth = (1080f / 1920f) * curHeight; //bgList[i].GetComponent().sizeDelta = new Vector2(curWidth, curHeight); if (Screen.height >= 1920) { float curWidth = (1080f / 1920f) * Screen.height; //Debug.Log("Screen.height " + Screen.height+ " curWidth "+ curWidth); bgList[i].GetComponent().sizeDelta = new Vector2(curWidth, Screen.height); } else { bgList[i].GetComponent().sizeDelta = new Vector2(1080, 1920) * 1.2f; } } } } }