using UnityEngine;
using System.Collections;
//根据设备的宽高比,调整camera.orthographicSize. 以保证UI在不同分辨率(宽高比)下的自适应
//须与UIAnchor配合使用
//将该脚本添加到UICamera同一节点上
[RequireComponent(typeof(UICamera))]
public class UICameraAdjustor : MonoBehaviour
{
float standard_width = 1136f;
float standard_height = 640f;
float device_width = 0f;
float device_height = 0f;
void Awake()
{
device_width = Screen.width;
device_height = Screen.height;
SetCameraSize();
}
private void SetCameraSize()
{
float adjustor = 0f;
float standard_aspect = standard_width / standard_height;
float device_aspect = device_width / device_height;
if (device_aspect < standard_aspect)
{
adjustor = standard_aspect / device_aspect;
camera.orthographicSize = adjustor;
}
}
}
NGUI 自适应拓展
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 优点:简单 缺点:不兼容IE6 优点:兼容性好 缺点:结构多一点 优点:样式简单 缺点:不兼容IE6 同样适用于不...
- 思考几个问题 TextView 如果userInteractionEnabled为NO可以当label使用吗?Te...