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 |

1 using UnityEngine;
2 using System.Collections;
3
4 /// <summary>
5 /// 根据设备的宽高比,调整camera.orthographicSize. 以保证UI在不同分辨率(宽高比)下的自适应
6 /// 须与UIAnchor配合使用
7 /// 将该脚本添加到UICamera同一节点上
8 /// </summary>
9
10 [RequireComponent(typeof(UICamera))]
11 public class UICameraAdjustor : MonoBehaviour
12 {
13 float standard_width = 1024f;
14 float standard_height = 600f;
15 float device_width = 0f;
16 float device_height = 0f;
17
18 void Awake()
19 {
20 device_width = Screen.width;
21 device_height = Screen.height;
22
23 SetCameraSize();
24 }
25
26 private void SetCameraSize()
27 {
28 float adjustor = 0f;
29 float standard_aspect = standard_width / standard_height;
30 float device_aspect = device_width / device_height;
31
32 if (device_aspect < standard_aspect)
33 {
34 adjustor = standard_aspect / device_aspect;
35 camera.orthographicSize = adjustor;
36 }
37 }
38 }


1 using UnityEngine;
2 using System.Collections;
3
4 /// <summary>
5 /// 根据设备的宽高比,调整UISprite scale, 以保证全屏的背景图在不同分辨率(宽高比)下的自适应
6 /// 将该脚本添加到UISprite同一节点上
7 /// 须与UICameraAdjustor脚本配合使用
8 /// </summary>
9
10 [RequireComponent(typeof(UISprite))]
11 public class UIBackgroundAdjustor : MonoBehaviour
12 {
13 float standard_width = 1024f;
14 float standard_height = 600f;
15 float device_width = 0f;
16 float device_height = 0f;
17
18 void Awake()
19 {
20 device_width = Screen.width;
21 device_height = Screen.height;
22
23 SetBackgroundSize();
24 }
25
26 private void SetBackgroundSize()
27 {
28 UISprite m_back_sprite = GetComponent<UISprite>();
29
30 if (m_back_sprite != null && UISprite.Type.Simple == m_back_sprite.type)
31 {
32 m_back_sprite.MakePixelPerfect();
33 float back_width = m_back_sprite.transform.localScale.x;
34 float back_height = m_back_sprite.transform.localScale.y;
35
36 float standard_aspect = standard_width / standard_height;
37 float device_aspect = device_width / device_height;
38 float extend_aspect = 0f;
39 float scale = 0f;
40
41 if (device_aspect > standard_aspect) //按宽度适配
42 {
43 scale = device_aspect / standard_aspect;
44
45 extend_aspect = back_width / standard_width;
46 }
47 else //按高度适配
48 {
49 scale = standard_aspect / device_aspect;
50
51 extend_aspect = back_height / standard_height;
52 }
53
54 if (extend_aspect >= scale) //冗余尺寸足以适配,无须放大
55 {
56 }
57 else //冗余尺寸不足以适配,在此基础上放大
58 {
59 scale /= extend_aspect;
60 m_back_sprite.transform.localScale *= scale;
61 }
62 }
63 }
64 }
Unity3d + NGUI 的多分辨率适配的更多相关文章
- 【转】Unity3d + NGUI 的多分辨率适配
原文地址:http://www.cnblogs.com/cqgreen/p/3348154.html 一.当下移动设备的主流分辨率(数据来自“腾讯分析移动设备屏幕分辨率分析报告”) 1.1 iOS ...
- 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. ...
随机推荐
- 第二节(RequestMapping请求方式)学习尚硅谷-springmvc视频教程
项目中,创建测试类SpringMVCTest @Controller @RequestMapping("/springmvc1") public class SpringMVCTe ...
- mysql: update字段中带select
update字段中带select UPDATE tb_report_type A INNER JOIN (SELECT LEVEL_CODE FROM tb_report_type WHERE id ...
- OD使用教程7
破解程序获得使用权限: 破解思路:其实程序加密或者添加neg窗口都是为了让消费者付出更多的代价来解决这些问题.然而身为一个技术人员是可以靠技术来使这些东西消失的.只要我们找到那些东西出现的 ...
- BZOJ1261: [SCOI2006]zh_tree
Description 张老师根据自己工作的需要,设计了一种特殊的二叉搜索树.他把这种二叉树起名为zh_tree,对于具有n个结点的zh_tree,其中序遍历恰好为(1,2,3,-,n),其中数字1, ...
- 16.iOS APP图标和启动画面尺寸
1. 桌面图标 (app icon) for iPhone6 plus(@3x) : 180 x 180 for iPhone 6/5s/5/4s/4(@2x) : 120 x 120 2. 系统搜索 ...
- Linux最常用命令之cd和ls
为什么说是最常用的命令呢,因为从普及程度看,即使不怎么接触过Linux系统的人,大多数都会知道这两个命令:而从使用频率看,这两个命令也是当之无愧的首位.现在我们就来看看这两个命令. cd 篇:cd 即 ...
- Java学习笔记 01 基本数据类型、标识符、关键字和运算符
一.基本数据类型 基本数据类型 数据类型 内存空间(8位等于1字节) 取值范围 备注 byte 8位 -128~127 short 16位 -32768~32767 int 32位 -2147 ...
- Mysql --分区表的管理与维护
改变一个表的分区方案只需使用alter table 加 partition_options 子句就可以了.和创建分区表时的create table语句很像 创建表 CREATE TABLE trb3 ...
- NRF24L01--使用STM32F103
看了两天的24l01的相关资料了,一直有点模糊,今天下午感觉有点懂了,在板子上调试成功了,但是还没进行通讯测试.stm32和arduino进行通信还没成功 ,:( 先把stm32的NRF24L01配置 ...
- reduce方法
API里面这样写 reduce(initial, sym) → obj reduce(初始值,符号) reduce(sym) → obj re ...