UIScreenAdaptive
2024-08-26 22:38:36
using UnityEngine; namespace Com.Xyz.UI
{
[ExecuteInEditMode]
[RequireComponent(typeof(UIRoot))]
public class UIScreenAdaptive : MonoBehaviour
{
public int aspectRatioWidth = ;
public int aspectRatioHeight = ;
public bool runOnlyOnce = false;
private UIRoot mRoot;
private bool mStarted = false; private void Awake()
{
UICamera.onScreenResize += OnScreenResize;
} private void OnDestroy()
{
UICamera.onScreenResize -= OnScreenResize;
} private void Start()
{
mRoot = NGUITools.FindInParents<UIRoot>(this.gameObject); mRoot.scalingStyle = UIRoot.Scaling.FixedSize; this.Update();
mStarted = true;
} private void OnScreenResize()
{
if (mStarted && runOnlyOnce)
{
this.Update();
}
} private void Update()
{
float defaultAspectRatio = aspectRatioWidth * 1f / aspectRatioHeight;
float currentAspectRatio = Screen.width * 1f / Screen.height; if (defaultAspectRatio > currentAspectRatio)
{
int horizontalManualHeight = Mathf.FloorToInt(aspectRatioWidth / currentAspectRatio);
mRoot.manualHeight = horizontalManualHeight;
}
else
{
mRoot.manualHeight = aspectRatioHeight;
} if (runOnlyOnce && Application.isPlaying)
{
this.enabled = false;
}
}
}
}
最新文章
- Behind RabbitMQ Exchange Types
- 未完结第八节 JBPM流程节点
- php修改和增加xml结点属性
- linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析(引用)
- 编写高效SQL最佳实践
- CUGBACM_Summer_Tranning 组队赛解题报告
- php实现和c#一致的DES加密解密
- Java课程设计—学生成绩管理系统
- 如何更简单方便地执行SQL操作?
- SQOOP安装部署
- SHELL-收集Oracle已应用的PSU信息
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭
- OpenGL 画出雷达动态扫描效果(二) 非底图
- HTML转义
- 软件魔方制作系统启动盘并安装win8系统
- HTTPS链式编程——AFNetworking 3.0
- Android 集成百度统计
- 队列 102 Binary Tree Level Order Traversal
- salt demo 环境
- 重复造轮子系列--dijkstra算法
热门文章
- 使用bottle进行web开发(6):Response 对象
- 【互动问答分享】第7期决胜云计算大数据时代Spark亚太研究院公益大讲堂
- mimikatz-域密码获取神器
- HDU 5969 最大的位或【贪心/按位或/思维】
- poj2778(AC 自动机)
- python3-关于GitHub的最基本操作
- 1.6(学习笔记)Session
- [SourceTree]--记录Win10 安装SourceTree免注册登陆
- iOS 10 资料整理笔记
- iOS开发技巧&mdash;&mdash;关闭Autoresizing开启Autolayout