如何放置相机以使其完整显示可变大小的 2d 区域?
How to place the camera so that it shows a 2d area of variable size in full?
我正在制作一个生成二维区域(您可以将其视为绘图)的应用程序,相机悬停在其上方。所述图纸的尺寸事先不知道,并且可能会发生很大变化。 "drawing" 生成后,我想定位相机,以便可以看到整个绘图。
我最初的想法是计算图形的顶部、底部、左侧和右侧的点,然后让相机向后移动,"zooming out"直到它们都在视线范围内,但是有是更好的方法,对吧?
假设您在 2D 模式下工作(因此正交相机模式),您可以设置 camera
的 orthographicSize
:
Camera.main.orthographicSize = height / 2F; //half of the height of the area
然后,设置aspect
比例(宽/高):
Camera.main.aspect = 1F; //for example, a square area
我正在制作一个生成二维区域(您可以将其视为绘图)的应用程序,相机悬停在其上方。所述图纸的尺寸事先不知道,并且可能会发生很大变化。 "drawing" 生成后,我想定位相机,以便可以看到整个绘图。
我最初的想法是计算图形的顶部、底部、左侧和右侧的点,然后让相机向后移动,"zooming out"直到它们都在视线范围内,但是有是更好的方法,对吧?
假设您在 2D 模式下工作(因此正交相机模式),您可以设置 camera
的 orthographicSize
:
Camera.main.orthographicSize = height / 2F; //half of the height of the area
然后,设置aspect
比例(宽/高):
Camera.main.aspect = 1F; //for example, a square area