Unity2D屏幕适配方案
2015-09-30 10:14
375 查看
看了cnblogs里的一篇文章,终于理解了Unity2D的摄像机系统:http://www.cnblogs.com/flyFreeZn/p/4073655.html
我根据他的方案,改写了两种适配方案:fixedWidth和fixedHeight,就是锁定其中一个变量来适配屏幕。
你可以修改设计尺寸,记住设计尺寸是通过1:100比例缩放后的。
我根据他的方案,改写了两种适配方案:fixedWidth和fixedHeight,就是锁定其中一个变量来适配屏幕。
using UnityEngine; using System.Collections; public class GameCamera : MonoBehaviour { public string scaleMode = "fixedWidth"; public float designWidth = 9.6f; public float designHeight = 16f; // Use this for initialization void Start () { float aspectRatio = Screen.width * 1.0f / Screen.height; float orthographicSize = 0; switch (scaleMode) { case "fixedWidth": orthographicSize = designWidth / (2 * aspectRatio); break; case "fixedHeight": orthographicSize = designHeight / 2; break; } this.GetComponent<Camera>().orthographicSize = orthographicSize; Debug.Log (orthographicSize); } // Update is called once per frame void Update () { } }
你可以修改设计尺寸,记住设计尺寸是通过1:100比例缩放后的。
相关文章推荐
- unity破解步骤
- Unity_事件函数
- Shader入门指南【1】
- unity 基于Assetbundle的更新机制的设计
- 全面理解 Unity UI 系统
- unity3d C#语言基础(继承)
- Unity3D之碰撞体,刚体
- Unity3D中的一些Atrribute
- 【Unity】UGUI中RectTransform中Top和Bottom的设置,宽和高的设置,以及postion和锚点的设置
- [Unity3D学习]3D数学基础之坐标系
- 【Unity】UGUI怎么计算RectTransform中的Top和Bottom的值
- Unity 5.x的专用插件推荐
- Unity5 如何做资源管理和增量更新
- Unity抛物线AddForce计算
- Unity笔记 2D Best Practices (2D IK 骨骼动画 event 换装 蒙皮 排序)
- Unity3d:NGUI所见即所得之UIWidget , UIGeometry & UIDrawCall
- Unity5的AssetBundle的一点使用心得
- Unity3d中对应各平台Path
- ubuntu 14.04无法进入unity
- Unity3d NGUI的UILabel中文字体及可点击的字体