UIScreenAdaptive
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;
}
}
}
}
UIScreenAdaptive的更多相关文章
- ngui自适应
增加UIROOT using UnityEngine; namespace Com.Xyz.UI { [ExecuteInEditMode] [RequireComponent(typeof(UIRo ...
随机推荐
- LAMP安装细则
利用xshell从Windows向Linux传输文件[root@nanainux ~]#yum install lrzsz[root@nanalinux ~]#rz MySq二进制包安装 mysql ...
- hdu 5167(dfs)
Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- poj 2398(叉积判断点在线段的哪一侧)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5016 Accepted: 2978 Descr ...
- [BZOJ1492] [NOI2007]货币兑换Cash 斜率优化+cdq/平衡树维护凸包
1492: [NOI2007]货币兑换Cash Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5907 Solved: 2377[Submit][Sta ...
- python 文件路径操作方法(转)
Python编程语言在实际使用中可以帮助我们轻松的实现一些特殊的功能需求.在这里我们将会为大家详细介绍一下有关Python文件路径的相关操作技巧,从而方便我们在实际开发中获得一些帮助. Python文 ...
- python数据转换工具Into
转:http://python.jobbole.com/81564/ 再次介绍Into包:整洁地数据迁移 2015/03/12 · 基础知识 · into, 数据迁移 分享到:3 本文由 伯乐在线 ...
- 将双击“root的主文件”弹出的窗口设置为文件浏览器
1.双击桌面"root的文件夹"图标, 在过去Centos版本之前,每次双击“root主文件夹”都会弹出文件管理窗口: 解决办法: 关闭所有窗口后,重新双击图标: ...
- HDU1213 How Many Tables (并查集)
题目大意: 有一个人要过生日了,请他的朋友来吃饭,但是他的朋友互相认识的才能坐在一起,朋友的编号从1 ~ n,输入的两个数代表着这两个人互相认识(如果1和2认识,2和3认识,那么1和3也就认识了).问 ...
- LCIS最长公共上升子序列
最长公共上升子序列LCIS,如字面意思,就是在对于两个数列A和B的最长的单调递增的公共子序列. 这道题目是LCS和LIS的综合. 在LIS中,我们通过两重循环枚举当序列以当前位置为结尾时,A序列中当前 ...
- SetTimer()函数使用
在编程时,会经常使用到定时器.使用定时器的方法比较简单,通常告诉Windows一个时间间隔,然后WINDOWS以此时间间隔周期性触发程序.通常有两种方法来实现:发送WM_TIMER消息和调用应用程序定 ...