Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PixelsToPoints

Convert a Rect from pixel space to point space.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

PixelsToPoints(Rect)

Convert a Rect from pixel space to point space.
public static Rect PixelsToPoints(Rect rect)

Parameters

rect

A GUI rect measured in pixels.

Returns

Type

Description

RectA rect representing the same area in points.

Remarks

Convert from pixel space to point space.
Use this to convert values from custom content for use in GUI. For instance, you might be rendering a camera to a render texture, and then drawing GUI on top of that. Screen positions from the camera will be in pixel space, and need to be converted to points before being used for your UI.

PixelsToPoints(Vector2)

Convert a position from pixel to point space.
public static Vector2 PixelsToPoints(Vector2 position)

Parameters

position

A GUI position in pixel space.

Returns

Type

Description

Vector2A vector representing the same position in point space.

PixelsToPoints(Vector2, float)

Convert from pixel space to point space.
public static Vector2 PixelsToPoints(Vector2 position, float scaling)

Parameters

position


scaling

Returns

Type

Description

Vector2

Remarks

Use this to convert values from custom content for use in GUI. For instance, you might be rendering a camera to a render texture, and then drawing GUI on top of that. Screen positions from the camera will be in pixel space, and need to be converted to points before being used for your UI.