I am trying to get the bounds from an orthographic camera in Unity which take into account the current orthographic size (zoom).
I thought that I could use the cameraToWorldMatrix to transform the camera pixel rectangle into world coordinates.
var m = camera.cameraToWorldMatrix; var bL = m.MultiplyPoint(new Vector3(camera.pixelRect.xMin, camera.pixelRect.yMin)); var uL = m.MultiplyPoint(new Vector3(camera.pixelRect.xMin, camera.pixelRect.yMax)); var uR = m.MultiplyPoint(new Vector3(camera.pixelRect.xMax, camera.pixelRect.yMax)); var rect = new Rect(uL.x, uL.y, Math.Abs(uR.x - uL.x), Math.Abs(bL.y - uL.y));
However, this does not take into account the orthographic size (zoom).
Multiplying the cameraToWorldMatrix with the camera's projectionMatrix property does not give me the correct results either.
Is there a sensible way that this can be solved?