Unity2D屏幕適配方案

看了cnblogs裏的一篇文章,終於理解了Unity2D的攝像機系統:http://www.cnblogs.com/flyFreeZn/p/4073655.htmlhtml

我根據他的方案,改寫了兩種適配方案:fixedWidth和fixedHeight,就是鎖定其中一個變量來適配屏幕。this

 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比例縮放後的。spa

相關文章
相關標籤/搜索