Screen Placement

The EZScreenPlacement component (found in the Components menu under EZ GUI->Utility->EZ Screen Placement) provides a way to position objects in the scene in a manner that is independent of screen resolution or aspect ratio.

EZScreenPlacement allows you to specify that an object (including a non-EZ GUI object) should be placed in the scene either relative to one of the screen's edges, the screen center, or relative to another object in the scene. The distances from each of these frames of reference are given in pixel units. For example, you can tell an object to position itself 10 pixels from the left edge of the screen, and 10 pixels down from the top of the screen, regardless of resolution or aspect ratio.

NOTE: For performance reasons, this component does not update every frame, so if the resolution changes, or an object moves that is set as the "Relative Object", the EZScreenPlacement component will not automatically update the object's position. If one of these events occurs, or for any other reason you want the object to recompute its position on-screen, simply call the component's PositionOnScreen() method, or its SetCamera() method. In addition to these, if SetCamera() is called on a sprite-based EZ GUI object, any attached EZScreenPlacement component will automatically be called as well.
Using EZScreenPlacement
  1. Select the GameObject you wish to position, and then either drag the EZScreenPlacement script onto it, or add it through the component menu (Components->EZ GUI->Utility->EZ Screen Placement).

  2. Verify that the "Render Camera" field is pointing to the camera that will be rendering the object. This is important since placement calculations will be done using this camera, so if the wrong camera is selected, the object will not be properly positioned.

  3. Select what the object will be positioned relative to (the reference points). This is set using the "Relative To" field. See the table below for a description of all possible settings.

  4. Using the "Screen Pos" field, specify the number of pixels the object will be offset from the reference points (set in "Relative To" above), as well as the distance into the scene from the camera (the Z value). Note that positive X values will place an object to the right of the horizontal reference point, and positive Y values will place the object below the vertical reference point.
Render Camera
The camera which will be used to render and position this object. It is critical to proper placement that the correct camera be selected here.
Screen Pos
The number of screen pixels that the object should be offset from the reference points specified in the "Relative To" field. Positive X values will place the object to the right of the horizontal reference point, while positive Y values will place the object below the vertical reference point. The Z value determines how far, in world units, into the scene the object should be positioned in front of the camera.
Relative To
This field has two sub-fields.

Horizontal - This determines what the object will be positioned relative to on the horizontal axis. The options are:

  • NONE - The object's position will be unaltered on the horizontal axis.
  • SCREEN_LEFT - The X value in "Screen Pos" will be relative to the screen's left edge.
  • SCREEN_RIGHT - The X value in "Screen Pos" will be relative to the screen's right edge.
  • SCREEN_CENTER - The X value in "Screen Pos" will be relative to the screen's center.
  • OBJECT - The X value in "Screen Pos" will be relative to another object's position.

Vertical - This determines what the object will be positioned relative to on the vertical axis. The options are:

  • NONE - The object's position will be unaltered on the vertical axis.
  • SCREEN_TOP - The Y value in "Screen Pos" will be relative to the screen's top edge.
  • SCREEN_BOTTOM - The Y value in "Screen Pos" will be relative to the screen's bottom edge.
  • SCREEN_CENTER - The Y value in "Screen Pos" will be relative to the screen's center.
  • OBJECT - The Y value in "Screen Pos" will be relative to another object's position.
Relative Object
This setting is only used if one or both of the fields of "Relative To" are set to OBJECT. When that is the case, the GameObject will be positioned relative to the object specified by "Relative Object".
Always Recursive
When true, positioning of the object is always done in a recursive fashion. That is, if this object is relative to any other objects, those objects, should they also hold an EZScreenPlacement component, will be positioned before this one to ensure proper positioning.
Allow Transform Drag
When checked, you can simply use the transform handles in the scene view to roughly position your object in the scene, and the appropriate values will be automatically calculated for Screen Pos based on your other settings.

If you're having problems with slight rounding errors making small changes to your Screen Pos coordinate, you should probably uncheck this option. This is particularly likely to happen if your camera is rotated at all.
Calling from script

The most important methods available via script are the PositionOnScreen() methods, which allow you to re-position the object by specifying new coordinates for the screenPos setting. If you alter any of the relativeTo values at runtime, call PositionOnScreen() to apply them. More information about all the available methods, as well as details on their use, can be found in the scripting reference.