1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using UnityEngine;
- namespace Utility.UIAdapter
- {
- public class CameraAdapter : MonoBehaviour
- {
- private float _width;
- private float _height;
- /// <summary>
- /// 宽高比
- /// </summary>
- private float _ratio;
- private float _defaultFOV = 50;
- private Vector2 _sizeDelta;
- /// <summary>
- /// 设计宽高比
- /// </summary>
- private float _designRatio;
- private Camera _camera;
- void Start()
- {
- _width = Screen.width;
- _height = Screen.height;
- _ratio = _width / _height;
- _designRatio = 1334f / 750f;
- _camera = gameObject.GetComponent<Camera>();
- if (_camera.orthographic)
- {
- _camera.orthographicSize = _designRatio / _ratio * _camera.orthographicSize;
- }
- else
- {
- if (_designRatio / _ratio * _defaultFOV < 50)
- {
- _camera.fieldOfView = 50;
- }
- else
- {
- _camera.fieldOfView = _designRatio / _ratio * _defaultFOV;
- }
- }
- }
- }
- }
|