【转】Unity3d + NGUI 的多分辨率适配
宽 | 高 | 宽高比 |
960 | 640 | 1.5 |
1136 | 640 | 1.775 |
1024 | 768 | 1.3333 |
2048 | 1536 | 1.3333 |
宽 | 高 | 宽高比 |
800 | 480 | 1.6667 |
854 | 480 | 1.7792 |
1280 | 720 | 1.7778 |
960 | 540 | 1.7778 |
1280 | 800 | 1.6 |
960 | 640 | 1.5 |
1184 | 720 | 1.6444 |
1920 | 1080 | 1.7778 |
using UnityEngine;
using System.Collections; /// <summary>
/// 根据设备的宽高比,调整camera.orthographicSize. 以保证UI在不同分辨率(宽高比)下的自适应
/// 须与UIAnchor配合使用
/// 将该脚本添加到UICamera同一节点上
/// </summary>
[RequireComponent(typeof (UICamera))]
public class UICameraAdjustor : MonoBehaviour
{
private float standard_width = 1024f;
private float standard_height = 600f;
private float device_width = 0f;
private float device_height = 0f; private 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;
}
}
}
using UnityEngine;
using System.Collections; /// <summary>
/// 根据设备的宽高比,调整UISprite scale, 以保证全屏的背景图在不同分辨率(宽高比)下的自适应
/// 将该脚本添加到UISprite同一节点上
/// 须与UICameraAdjustor脚本配合使用
/// </summary>
[RequireComponent(typeof (UISprite))]
public class UIBackgroundAdjustor : MonoBehaviour
{
private float standard_width = 1024f;
private float standard_height = 600f;
private float device_width = 0f;
private float device_height = 0f; private void Awake()
{
device_width = Screen.width;
device_height = Screen.height; SetBackgroundSize();
} private void SetBackgroundSize()
{
UISprite m_back_sprite = GetComponent<UISprite>(); if (m_back_sprite != null && UISprite.Type.Simple == m_back_sprite.type)
{
m_back_sprite.MakePixelPerfect();
float back_width = m_back_sprite.transform.localScale.x;
float back_height = m_back_sprite.transform.localScale.y; float standard_aspect = standard_width/standard_height;
float device_aspect = device_width/device_height;
float extend_aspect = 0f;
float scale = 0f; if (device_aspect > standard_aspect) //按宽度适配
{
scale = device_aspect/standard_aspect; extend_aspect = back_width/standard_width;
}
else //按高度适配
{
scale = standard_aspect/device_aspect; extend_aspect = back_height/standard_height;
} if (extend_aspect >= scale) //冗余尺寸足以适配,无须放大
{
}
else //冗余尺寸不足以适配,在此基础上放大
{
scale /= extend_aspect;
m_back_sprite.transform.localScale *= scale;
}
}
}
}
【转】Unity3d + NGUI 的多分辨率适配的更多相关文章
- Unity3d + NGUI 的多分辨率适配
一.当下移动设备的主流分辨率(数据来自“腾讯分析移动设备屏幕分辨率分析报告”) 1.1 iOS设备的分辨率主要有: 宽 高 宽高比 960 640 1.5 1136 640 1.775 1024 ...
- Unity3d + NGUI 的多分辨率适配(黑边)
原地址:http://www.2cto.com/kf/201310/250921.html 一.当下移动设备的主流分辨率(数据来自“腾讯分析移动设备屏幕分辨率分析报告”) 1.1 iOS设备的分辨率主 ...
- Unity NGUI的多分辨率适配
参考链接:http://blog.csdn.net/mfc11/article/details/17681429,作者:CSDN mfc11 1.NGUI默认的适配方式: NGUI默认是适配方式是根据 ...
- Unity3d + UGUI 的多分辨率适配
原文地址:http://blog.csdn.net/dingkun520wy/article/details/49471789 1.Canvas的属性配置 2.Canvas Scaler的属性配置 3 ...
- Unity3D NGUI自适应屏幕分辨率(2014/4/17更新)
原地址:http://blog.csdn.net/asd237241291/article/details/8126619 原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 本文链接地址: ...
- Cocos与Cocos2d-x协作教程——多分辨率适配
http://www.cocoachina.com/bbs/read.php?tid-288123.html Cocos v2.1开始新增了一种新的多分辨率适配方案:流式布局. 这种布局相比Cocos ...
- Android多分辨率适配
前一阶段开发android项目,由于客户要求进行多分辨率适配,能够支持国内主流的分辨率手机.因此经过了几次开发走了很多弯路,目前刚刚领略了android多分辨率适配的一些方法. 先介绍一下所走的弯路, ...
- Android多分辨率适配经验总结
Android多分辨率适配是一件很有意义但是比较麻烦的事情,网上有很多关于多分辨率适配的文章,多数文章讲解的都是整个APP的图片比较规则,可以将图片做成9图来完成多分辨率适配,但是对于一些游戏类应 ...
- Unity3D NGUI学习(一)血条
这次来讲讲Unity3D NGUI这个插件的学习,这个插件是收费的,不过去网上可以下载得很多可用版本.用来做用户的交互UI,学习起来比较简单 第一步,导入NGUI包 http://pan.baidu. ...
随机推荐
- MySQL之存储引擎MyISAM/InnoDB高并发优化经验
https://www.centos.bz/2011/09/mysql-myisam-innodb-optimization-experience/
- Java 根据当前时间获取明天、当前周的周五、当前月的最后一天
private Date getDateByType(Date date, Integer type) { Calendar calendar = Calendar.getInstance(); ca ...
- 以forin的方式遍历数组时进行删除操作的注意点
今天在修改某项需求的时候,需要在遍历的时候将匹配项移除掉,采用的时forin的方式遍历,然后运行的时候却crash掉了 for (NSString*str in self.btnArray) { if ...
- Node.js EventEmitter(事件队列)
Node.js 所有的异步 I/O 操作在完成时都会发送一个事件到事件队列. Node.js里面的许多对象都会分发事件:一个net.Server对象会在每次有新连接时分发一个事件, 一个fs.read ...
- [转]http-关于application/x-www-form-urlencoded等字符编码的解释说明
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型. 下边是说明: application/x-www-form-urlen ...
- Java: IO 学习小结
源: 键盘 System.in 硬盘 FileStream 内存 ArrayStream 目的: 控制台 System.out 硬盘 FileStream 内存 ArrayStream 处理大文件或者 ...
- CASS 2008的野外操作码
表D-1 线面状地物符号代码表 坎类(曲): K(U) + 数(0-陡坎,1-加固陡坎,2-斜坡,3-加固斜坡,4-垄,5-陡崖,6-干沟) 线类(曲): X(Q) + 数(0-实线,1-内 ...
- [css]水平垂直居中的方法
1.top:cale(50% - 2rem); left:cale(50% - 2rem);
- Android中的布局动画
简介 布局动画是给布局的动画,会影响到布局中子对象 使用方法 给布局添加动画效果: 先找到要设置的layout的id,然后创建布局动画,创建一个LayoutAnimationController,并把 ...
- Ubuntu上安装MySql过程,以及遇到的一些问题
今天在Ubuntu服务器上安装MySql的时候遇到了一些问题,记录下来,以防以后忘记. 安装环境:Ubuntu14.04 安装命令: //安装Mysal服务端//会提示输入root密码 sudo ap ...