Unity2D屏幕适配方案

看了cnblogs里的一篇文章,终于理解了Unity2D的摄像机系统:http://www.cnblogs.com/flyFreeZn/p/4073655.html

我根据他的方案,改写了两种适配方案:fixedWidth和fixedHeight,就是锁定其中一个变量来适配屏幕。

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class GameCamera : MonoBehaviour {
 5     public string scaleMode = "fixedWidth";
 6 
 7     public float designWidth = 9.6f;
 8     public float designHeight = 16f;
 9     
10     // Use this for initialization
11     void Start () {
12         float aspectRatio = Screen.width * 1.0f / Screen.height;
13         float orthographicSize = 0;
14 
15         switch (scaleMode) {
16         case "fixedWidth":
17             orthographicSize = designWidth / (2 * aspectRatio);
18             break;
19         case "fixedHeight":
20             orthographicSize = designHeight / 2;
21             break;
22         }
23 
24         this.GetComponent<Camera>().orthographicSize = orthographicSize;
25         Debug.Log (orthographicSize);
26     }
27     
28     // Update is called once per frame
29     void Update () {
30         
31     }
32 }

你可以修改设计尺寸,记住设计尺寸是通过1:100比例缩放后的。

转载于:https://www.cnblogs.com/rockyf/p/4848411.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值