动态切换横竖屏
/// <summary>
/// 切换为横屏
/// </summary>
private void SetOrientationLandscape()
{
//设置横屏
Screen.orientation = ScreenOrientation.Landscape;
//设置横屏画布标准分辨率,保证UI横竖屏一致
scaler.referenceResolution = new Vector2(1920, 1080);
//这个match比例一般情况是这样,可根据项目情况设置
scaler.matchWidthOrHeight = 1;
}
/// <summary>
/// 切换为竖屏
/// </summary>
public void SetOrientationPortrait()
{
//设置竖屏
Screen.orientation = ScreenOrientation.Portrait;
//设置竖屏画布标准分辨率
scaler.referenceResolution = new Vector2(1080, 1920);
scaler.matchWidthOrHeight = 0;
}