using UnityEngine; private float ratio = 1f; private float panelW; private float panelH; UIRoot root = GameObject.FindObjectOfType<UIRoot>(); if (root != null) { // 實際尺寸和設計尺寸比例 ratio = (float)root.activeHeight / Screen.height; }
// 設計尺寸 panelW = transform.GetComponent<UIPanel>().width; panelH = transform.GetComponent<UIPanel>().height;
// 實際尺寸 width = panelW * ratio; height = panelH * ratio;