- 2d游戏里面相机的Orthan.size确定的是高度,宽度是按照屏幕的宽高比计算出来的
cameraWidthSize = camera.Orthographic.size*(Screen.Width/Screen.height)
- 我在游戏里设置的分辨率是1080*1920
- 所以我在原先1920情况下设置的size=10,可以恰好把图片横向全部展示
-
- 这个时候用unity用10来计算
10*(Screen.Width/Screen.height)
- 就把宽度变小了
- 但是到了手机里就变成了这样
- 所以需要按照原先的宽度来重新计算size
public class CameraAdaper
{
float width = 1080;
float height = 1920;
public void SetCamera(Camera camera)
{
var realWidthSize = (camera.orthographicSize * (width / height));
Debug.Log($"width_{Screen.width}-height_{Screen.height}");
float val = realWidthSize / ((float)Screen.width / (float)Screen.height);
Debug.Log($"cameraSzie{val}");
camera.orthographicSize = val;
}
}
- https://www.cnblogs.com/flyFreeZn/p/4073655.html