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比例缩放后的。

posted @ 2015-09-30 10:14  RockyF  阅读(1016)  评论(0编辑  收藏  举报