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

我根据他的方案,改写了两种适配方案: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 = ; switch (scaleMode) {
case "fixedWidth":
orthographicSize = designWidth / ( * aspectRatio);
break;
case "fixedHeight":
orthographicSize = designHeight / ;
break;
} this.GetComponent<Camera>().orthographicSize = orthographicSize;
Debug.Log (orthographicSize);
} // Update is called once per frame
void Update () { }
}

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

04-07 09:11