1. 程式人生 > >Unity獲取實際尺寸和設計尺寸

Unity獲取實際尺寸和設計尺寸

fin tco col object blog wid ipa bject ati

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;

Unity獲取實際尺寸和設計尺寸