Class TargetIndicatorManager
Tracks targets and transforms their world space positions into screen space coordinates with options to clamp to the screen edges, absolute size, or a compass tape. Useful for displaying directions to targets and other positions in the environment.
Namespace: TargetIndicators
Assembly: TargetIndicators.dll
Syntax
public class TargetIndicatorManager : MonoBehaviour
Constructors
TargetIndicatorManager()
Declaration
public TargetIndicatorManager()
Properties
BottomPadding
The distance from the bottom edge of the screen for Padded boundary type. Multiplied by
BoundaryScale to get screen pixels.
Declaration
public float BottomPadding { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
BoundaryScale
The scale applied to LeftPadding, RightPadding, TopPadding,
BottomPadding, Width, and Height to convert them to screen pixels.
Defaults to 1, meaning those values are in screen pixels.
Declaration
public float BoundaryScale { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Remarks
Set this to the scale factor of the UI that displays your visual indicators so the boundary is defined in
the same units as your UI and stays proportional to it at every resolution. For example, with a uGUI
CanvasScaler set to Scale With Screen Size, set this to Canvas.scaleFactor.
The manager does not read any UI system itself. The sample VisualIndicatorManager can keep this value
in sync with its canvas. If you build your own visual indicator system, you are responsible for setting this
value, and updating it whenever your UI scale changes (for example, when the screen resolution changes).
Values less than or equal to zero are rejected and log an error. Only Padded and Absolute
boundary types are affected.
BoundaryShape
The shape of the boundary to clamp target indicators to.
Declaration
public BoundaryShape BoundaryShape { get; set; }
Property Value
| Type | Description |
|---|---|
| BoundaryShape |
BoundaryType
The type of boundary to clamp target indicators to.
Declaration
public BoundaryType BoundaryType { get; set; }
Property Value
| Type | Description |
|---|---|
| BoundaryType |
CalculateLookAtDot
Gets or sets whether to calculate the dot product between the reference forward vector and the direction to the target. Enable this to use LookAtDot for advanced UI mechanics. Disable for a minor performance gain.
Declaration
public bool CalculateLookAtDot { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Camera
The scene camera that is used to calculate the screen pose of tracked targets. If this is null or destroyed, the manager will safely output default pose data for all targets, unless BoundaryType is CompassTape and CompassForwardReferenceOverride is set, in which case the override is used as the reference.
Declaration
public Camera Camera { get; set; }
Property Value
| Type | Description |
|---|---|
| Camera |
CompassForwardReferenceOverride
An optional transform used to override the forward reference vector when the BoundaryType is set to CompassTape. Useful for tracking targets relative to an independent object (like a vehicle hull) rather than a free-look camera. When set, compass tape poses do not require a Camera.
Declaration
public Transform CompassForwardReferenceOverride { get; set; }
Property Value
| Type | Description |
|---|---|
| Transform |
Ellipse
The definition of the currently configured ellipse in screen pixels, with BoundaryScale applied, if BoundaryShape is set to Ellipse.
Declaration
public Ellipse Ellipse { get; }
Property Value
| Type | Description |
|---|---|
| Ellipse |
Height
The height of the boundary centered at the screen center for Absolute boundary type. Multiplied by
BoundaryScale to get screen pixels.
Declaration
public float Height { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
LeftPadding
The distance from the left edge of the screen for Padded boundary type. Multiplied by
BoundaryScale to get screen pixels.
Declaration
public float LeftPadding { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
MaxTargets
The max number of targets that can be tracked.
Declaration
public int MaxTargets { get; }
Property Value
| Type | Description |
|---|---|
| int |
Rectangle
The definition of the currently configured rectangle in screen pixels, with BoundaryScale applied, if BoundaryShape is set to Rectangle.
Declaration
public Rect Rectangle { get; }
Property Value
| Type | Description |
|---|---|
| Rect |
RightPadding
The distance from the right edge of the screen for Padded boundary type. Multiplied by
BoundaryScale to get screen pixels.
Declaration
public float RightPadding { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
TopPadding
The distance from the top edge of the screen for Padded boundary type. Multiplied by
BoundaryScale to get screen pixels.
Declaration
public float TopPadding { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
TrackedTargetsCount
The current number of targets being tracked.
Declaration
public int TrackedTargetsCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Width
The width of the boundary centered at the screen center for Absolute boundary type. Multiplied by
BoundaryScale to get screen pixels.
Declaration
public float Width { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
GetChanges()
Manually processes world-to-screen transformations for all tracked targets and dispatches the corresponding added, updated, and removed events.
Declaration
public void GetChanges()
Remarks
Use this to synchronize indicator data and trigger events outside the standard
Update loop (for example, if this component is disabled, or you require mid-frame updates).
GetScreenPose(Vector3, out bool)
Gets the screen pose of a world space position. If there is no valid reference (see Camera),
this safely returns UnityEngine.Pose.identity and sets isOutsideBoundary to false.
Declaration
public Pose GetScreenPose(Vector3 worldSpacePosition, out bool isOutsideBoundary)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | worldSpacePosition | The world space position to convert to the screen pose. |
| bool | isOutsideBoundary |
|
Returns
| Type | Description |
|---|---|
| Pose | The screen space pose of |
IsOutsideBoundary(Vector3)
Checks if the screen space position is outside the configured boundary.
If the Camera is null, this will safely return false.
Declaration
public bool IsOutsideBoundary(Vector3 screenPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | screenPoint | The screen point to test. Requires the point as a |
Returns
| Type | Description |
|---|---|
| bool |
|
RemoveAllTargets()
Removes all targets that are being tracked.
Declaration
public void RemoveAllTargets()
TryAddTarget(Transform, out TargetIndicator)
Attempts to add a new target to be tracked. This can only fail if the TrackedTargetsCount
equals MaxTargets. If there is no valid reference (see Camera), the returned
targetIndicator will contain default pose data.
Declaration
public bool TryAddTarget(Transform target, out TargetIndicator targetIndicator)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | target | The transform of the target to track. |
| TargetIndicator | targetIndicator | The created TargetIndicator for the current frame of the target's position. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryGetTargetIndicator(TargetIndicatorId, out TargetIndicator)
Attempts to get the TargetIndicator for the corresponding TargetIndicatorId.
If there is no valid reference (see Camera), the returned targetIndicator
will contain default pose data.
Declaration
public bool TryGetTargetIndicator(TargetIndicatorId targetIndicatorId, out TargetIndicator targetIndicator)
Parameters
| Type | Name | Description |
|---|---|---|
| TargetIndicatorId | targetIndicatorId | The ID of the target indicator. |
| TargetIndicator | targetIndicator | The TargetIndicator associated with
|
Returns
| Type | Description |
|---|---|
| bool |
|
TryRemoveTarget(TargetIndicatorId)
Attempts to remove a target indicator.
Declaration
public bool TryRemoveTarget(TargetIndicatorId targetIndicatorId)
Parameters
| Type | Name | Description |
|---|---|---|
| TargetIndicatorId | targetIndicatorId | The ID of the target indicator to remove. |
Returns
| Type | Description |
|---|---|
| bool |
|
Events
TargetIndicatorsAdded
Invoked when target indicators have been added.
Declaration
public event TargetIndicatorManager.TargetIndicatorsUpdatedDelegate TargetIndicatorsAdded
Event Type
| Type | Description |
|---|---|
| TargetIndicatorManager.TargetIndicatorsUpdatedDelegate |
TargetIndicatorsRemoved
Invoked when target indicators have been removed.
Declaration
public event TargetIndicatorManager.TargetIndicatorsRemovedDelegate TargetIndicatorsRemoved
Event Type
| Type | Description |
|---|---|
| TargetIndicatorManager.TargetIndicatorsRemovedDelegate |
TargetIndicatorsUpdated
Invoked when target indicators have been updated.
Declaration
public event TargetIndicatorManager.TargetIndicatorsUpdatedDelegate TargetIndicatorsUpdated
Event Type
| Type | Description |
|---|---|
| TargetIndicatorManager.TargetIndicatorsUpdatedDelegate |