using System.Collections; using System.Collections.Generic; using UnityEngine; public class Fitter : MonoBehaviour { private Camera myCamera; private Camera myCameraUI; private Camera myCamera3D; private float width = 1080f; private float height = 1920f; private float size = 64f;//在1080*1920情况下的大小 private float ratio; // Start is called before the first frame update void Awake() { ratio = width / height; myCamera = GetComponent(); myCameraUI = GameObject.Find("UICamera").GetComponent(); myCamera3D = GameObject.Find("SceneCamera3D").GetComponent(); Calculate(); //myCamera.orthographicSize = myCamera.orthographicSize * 1920 / 1080 * Screen.height / Screen.width; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { Calculate(); } } void Calculate() { float tmpRatio = (float)Screen.width / (float)Screen.height; float newRatio = ratio - tmpRatio + 1.0f; Debug.Log($"开始变化大小,ratio:{ratio} tmpRatio:{tmpRatio} newRatio{newRatio}"); myCamera.orthographicSize = size * newRatio; if (myCameraUI != null){ myCameraUI.orthographicSize = size * newRatio; } if (myCamera3D != null) { myCamera3D.fieldOfView = 60 * newRatio; } } }