Unity获取实际尺寸和设计尺寸

Posted 色色0.o先生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity获取实际尺寸和设计尺寸相关的知识,希望对你有一定的参考价值。

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获取实际尺寸和设计尺寸的主要内容,如果未能解决你的问题,请参考以下文章