准备着手做款2d游戏。这两天在看各种资料。研究到ZenJect,一个unity3d下IOC的框架。解耦很厉害,但是一时有点难以接受,摸索中。研究其例子的时候,
看到一段代码,计算正交相机下,各边界的值。还是不错的,(如果用sprite制作2d游戏,这个值刚好方便判断各分辨率下上下左右的数值,单位非px)代码如下:
public class LevelHelper
{
readonly Camera _camera;
public LevelHelper(
[Inject(Id = "Main")]
Camera camera)
{
_camera = camera;
}
public float Bottom
{
get { return -ExtentHeight; }
}
public float Top
{
get { return ExtentHeight; }
}
public float Left
{
get { return -ExtentWidth; }
}
public float Right
{
get { return ExtentWidth; }
}
public float ExtentHeight
{
get { return _camera.orthographicSize; }
}
public float Height
{
get { return ExtentHeight * 2.0f; }
}
public float ExtentWidth
{
get { return _camera.aspect * _camera.orthographicSize; }
}
public float Width
{
get { return ExtentWidth * 2.0f; }
}
}
待补充....