Description
The Viewport
property of the Graphics
class specifies the pixel dimensions of the area where rendering occurs. This static property provides the size and position of the rendering target, which is crucial for determining the output area on the screen or within a texture.
Usage
Use the Viewport
property to get the current rendering dimensions in pixels. This is particularly useful when you need to perform operations that depend on the size of the rendering area, such as setting up camera projections or aligning UI elements.
Example
// Example of accessing the Viewport property
Rect currentViewport = Graphics.Viewport;
// Use the viewport dimensions for setting up a camera
Camera camera = new Camera();
camera.SetProjection(currentViewport.Width, currentViewport.Height);