Same visible area regardless of aspect ratio

来源:互联网 发布:华为软件培训 编辑:程序博客网 时间:2024/06/07 06:14
using System.Collections;using System.Collections.Generic;using UnityEngine;public class Test : MonoBehaviour {    // Use this for initialization    const float KEEP_ASPECT = 16 / 9f;    void Start()    {        float aspectRatio = Screen.width / ((float)Screen.height);        float percentage = 1 - (aspectRatio / KEEP_ASPECT);        Camera cam = GetComponent<Camera>();        cam.rect = new Rect(0f, (percentage / 2), 1f, (1 - percentage));    }    // Update is called once per frame    void Update () {}}


参考:

http://answers.unity3d.com/questions/23291/same-visible-area-regardless-of-aspect-ratio.html