简单相机自适应
小菜鸟
2021-11-19 PM
6642℃
0条
/// <summary>
/// 相机自适应类
/// </summary>
public class CameraAuto : MonoBehaviour
{
public float camInitSize;// 初始化视口大小
public float screne_width;// 初始化宽
public float screne_height;//初始化高
private float auto_size;//实际视口大小
private float auto_width;// 实际宽
private float auto_height;//实际高
// Start is called before the first frame update
void Start()
{
auto_width = Screen.width;
auto_height = Screen.height;
//正交相机自适应宽 公式: 实际视口 = 初始化视口大小 * 初始宽高比 / 实际宽高比
auto_size = (camInitSize * (screne_width / screne_height)) / (auto_width / auto_height);
GetComponent<Camera>().orthographicSize = auto_size;
}
}