您的位置:首页 > 移动开发 > Unity3D

Unity2D屏幕适配方案

2015-09-30 10:14 375 查看
看了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 = 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比例缩放后的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: