Class PrefabMarkerManager
Manages marker GameObjects positioned on the map.
public sealed class PrefabMarkerManager : MonoBehaviour
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourPrefabMarkerManager
Remarks
This is the only prefab-tier GameObject store. Map is a BaseMapView (screen or surface). BindView(BaseMapView, TabletopContentView) reparents the same instances and handles onto a table or back.
Fields
CaptionFont
[FormerlySerializedAs("FontOverride")]
[Tooltip("Caption font; empty = the map's global LabelFont.")]
public Font CaptionFont
Field Value
- Font
CaptionFontSize
[Tooltip("Caption font size.")]
public int CaptionFontSize
Field Value
CaptionTextColor
[Tooltip("Caption text color. Alpha 0 (the default) means no inline color: the on-map USS class's var(--text) and text-shadow show through unchanged.")]
public Color CaptionTextColor
Field Value
- Color
ClickSlopPx
[Tooltip("Pointer travel in pixels that turns a press-on-a-marker into a miss instead of Clicked/LongPressed.")]
public float ClickSlopPx
Field Value
DrawLabels
[Tooltip("Show Label text under markers and HoverText near the cursor.")]
public bool DrawLabels
Field Value
HideOffscreenMarkers
[Tooltip("Deactivate marker GameObjects while outside the viewport.")]
public bool HideOffscreenMarkers
Field Value
HoverBackground
[FormerlySerializedAs("DefaultBackground")]
[Tooltip("Hover card background color.")]
public Color HoverBackground
Field Value
- Color
HoverFont
[Tooltip("Hover card font; empty = the map's global LabelFont.")]
public Font HoverFont
Field Value
- Font
HoverFontSize
[FormerlySerializedAs("DefaultFontSize")]
[Tooltip("Hover card font size.")]
public int HoverFontSize
Field Value
HoverRadiusPx
[Tooltip("Hover radius in pixels when the prefab has no collider. Colliders win.")]
public float HoverRadiusPx
Field Value
HoverRaycastMask
[Tooltip("Layers hover raycasts test. Default everything. Excluded layers are not hoverable.")]
public LayerMask HoverRaycastMask
Field Value
- LayerMask
HoverScale
[Tooltip("Hovered marker grows by this factor (parity with the 2D tier).")]
public float HoverScale
Field Value
HoverTextColor
[FormerlySerializedAs("DefaultTextColor")]
[Tooltip("Hover card text color.")]
public Color HoverTextColor
Field Value
- Color
LockToMapRotation
[Tooltip("Rotate markers with the map bearing and pitch so they stay glued to the world instead of the screen.")]
public bool LockToMapRotation
Field Value
LongPressSeconds
[Tooltip("Hold this long on a marker (without moving past Click Slop Px) for LongPressed instead of Clicked.")]
public float LongPressSeconds
Field Value
Map
View this manager poses markers against (screen or surface).
public BaseMapView Map
Field Value
MaxPrefabGeneration
Reuses of one slot before it is retired.
public const int MaxPrefabGeneration = 524287
Field Value
MaxPrefabSlots
Slots this manager can ever hand out.
public const int MaxPrefabSlots = 4096
Field Value
ModelUpIsY
[Tooltip("Stand models upright: local +Y points out of the map plane (toward the viewer at pitch 0).")]
public bool ModelUpIsY
Field Value
OffscreenMarginPx
[Tooltip("Extra pixels around the screen still counted as visible.")]
public float OffscreenMarginPx
Field Value
OverlayWFloor
[Tooltip("Overlay markers, labels and trails stop rising once their perspective W reaches this floor, so a marker passing eye level slides off the top edge instead of vanishing mid-screen. Negative means compute it from the camera, which is the recommended setting. 0 disables the floor.")]
public float OverlayWFloor
Field Value
PlaneDistance
[Tooltip("Distance from camera at which markers are placed.")]
public float PlaneDistance
Field Value
Tabletop
Table this manager poses onto; empty poses on the screen camera plane.
[Tooltip("Table to pose markers on. Empty poses on the screen camera plane.")]
public TabletopContentView Tabletop
Field Value
TargetCamera
public Camera TargetCamera
Field Value
- Camera
TieBiasDepthFraction
How much real view depth, as a fraction of PlaneDistance, the 2D overlay tier is nudged toward the viewer so it wins an exact depth tie against 3D models.
public const double TieBiasDepthFraction = 0.001
Field Value
Properties
HiddenByCluster
public bool HiddenByCluster { get; set; }
Property Value
HoveredMarker
public WorldMarkerInstance HoveredMarker { get; }
Property Value
Markers
public IReadOnlyList<WorldMarkerInstance> Markers { get; }
Property Value
MercatorRecomputeCount
public int MercatorRecomputeCount { get; }
Property Value
ProjectionRefreshCount
public int ProjectionRefreshCount { get; }
Property Value
Methods
Adopt(GameObject, double, double, double, MarkerAltitudeMode)
Adopts an existing GameObject as a prefab-tier marker without instantiating and reparents it onto the table PrefabAnchor or this manager's Root.
public WorldMarkerInstance Adopt(GameObject go, double lat, double lon, double altitudeMeters, MarkerAltitudeMode altitudeMode = MarkerAltitudeMode.RelativeToGround)
Parameters
goGameObjectExisting GameObject to adopt; reparented onto the table PrefabAnchor or this manager's Root.
latdoubleLatitude in degrees WGS84.
londoubleLongitude in degrees WGS84.
altitudeMetersdoubleAuthored altitude in meters; meaning depends on
altitudeMode.altitudeModeMarkerAltitudeModeHow
altitudeMetersis resolved against sampled ground. Default RelativeToGround.
Returns
- WorldMarkerInstance
Handle this manager repositions on every view change.
Remarks
This manager overwrites the adopted GameObject's transform every frame to keep it map-anchored. Do not drive its position or rotation with a Rigidbody or other physics motion; that motion is overwritten every frame by the reprojection.
BindView(BaseMapView, TabletopContentView)
Points this manager at a screen or surface view and reparents every spawned GameObject onto the table PrefabAnchor or back onto this manager's Root.
public void BindView(BaseMapView map, TabletopContentView table)
Parameters
mapBaseMapViewView this manager poses against (screen or surface).
tableTabletopContentViewTable to pose onto; null poses on the screen camera plane.
Remarks
Same instances and same handles; this is the only prefab store.
Despawn(WorldMarkerInstance)
Destroys the marker GameObject and frees its prefab-tier id.
public void Despawn(WorldMarkerInstance marker)
Parameters
markerWorldMarkerInstanceInstance previously returned by Spawn or Adopt.
EffectiveCaptionFont(WorldMarkerInstance)
Effective caption font for m; the marker override, else this manager's font, else the map's LabelFont.
public Font EffectiveCaptionFont(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- Font
Font used to draw the on-map caption, or null.
EffectiveCaptionFontSize(WorldMarkerInstance)
Effective caption font size for m; the marker override if set, otherwise this manager's value.
public int EffectiveCaptionFontSize(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- int
Caption font size in panel px.
EffectiveCaptionTextColor(WorldMarkerInstance)
Effective caption text color for m; the marker override if set, otherwise this manager's value.
public Color EffectiveCaptionTextColor(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- Color
Caption RGBA; alpha 0 means no inline color.
EffectiveDrawLabels(WorldMarkerInstance)
Effective draw-labels for m; the marker override if set, otherwise this manager's value.
public bool EffectiveDrawLabels(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- bool
True when the on-map caption may draw for this marker.
EffectiveHideOffscreenMarkers(WorldMarkerInstance)
Effective hide-offscreen for m; the marker override if set, otherwise this manager's value.
public bool EffectiveHideOffscreenMarkers(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- bool
True when the marker deactivates while outside the viewport plus margin.
EffectiveHoverBackground(WorldMarkerInstance)
Effective hover-card background for m; the marker override if set, otherwise this manager's value.
public Color EffectiveHoverBackground(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- Color
Hover-card background RGBA.
EffectiveHoverFont(WorldMarkerInstance)
Effective hover-card font for m; the marker override, else this manager's font, else the map's LabelFont.
public Font EffectiveHoverFont(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- Font
Font used to draw the hover card, or null.
EffectiveHoverFontSize(WorldMarkerInstance)
Effective hover-card font size for m; the marker override if set, otherwise this manager's value.
public int EffectiveHoverFontSize(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- int
Hover-card font size in panel px.
EffectiveHoverRadiusPx(WorldMarkerInstance)
Effective hover radius for m; the marker override if set, otherwise this manager's value.
public float EffectiveHoverRadiusPx(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- float
Anchor-pick radius in screen px when the prefab has no collider.
EffectiveHoverScale(WorldMarkerInstance)
Effective hover scale for m; the marker override if set, otherwise this manager's value.
public float EffectiveHoverScale(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- float
Unitless factor the hovered marker grows by.
EffectiveHoverTextColor(WorldMarkerInstance)
Effective hover-card text color for m; the marker override if set, otherwise this manager's value.
public Color EffectiveHoverTextColor(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- Color
Hover-card text RGBA.
EffectiveLockToMapRotation(WorldMarkerInstance)
Effective lock-to-map-rotation for m; the marker override if set, otherwise this manager's value.
public bool EffectiveLockToMapRotation(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- bool
True when the marker rotates with map bearing and pitch.
EffectiveModelUpIsY(WorldMarkerInstance)
Effective model-up-is-Y for m; the marker override if set, otherwise this manager's value.
public bool EffectiveModelUpIsY(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- bool
True when local +Y points out of the map plane.
EffectiveOffscreenMarginPx(WorldMarkerInstance)
Effective offscreen margin for m; the marker override if set, otherwise this manager's value.
public float EffectiveOffscreenMarginPx(WorldMarkerInstance m)
Parameters
mWorldMarkerInstanceMarker whose override is consulted.
Returns
- float
Extra screen px around the viewport still counted as visible.
IsLive(int)
Whether handle still names a spawned prefab marker on this manager.
public bool IsLive(int handle)
Parameters
Returns
- bool
True while the marker is still in this manager's live list.
IsWithinClickSlop(Vector3, Vector3, float)
Whether pointer travel since press still counts as a click rather than a drag.
public static bool IsWithinClickSlop(Vector3 currentPos, Vector3 downPos, float slopPx)
Parameters
currentPosVector3Current pointer position in screen px.
downPosVector3Press position in screen px.
slopPxfloatAllowed travel in screen px.
Returns
- bool
True when the squared distance is at most slopPx squared.
IsWithinScreenMargin(WorldMarkerInstance, ScreenPoint)
Whether the projected point still counts as on-screen given m's offscreen margin.
public bool IsWithinScreenMargin(WorldMarkerInstance m, ScreenPoint s)
Parameters
mWorldMarkerInstanceMarker whose OffscreenMarginPx override is consulted.
sScreenPointProjected position in screen px, origin top-left.
Returns
- bool
True when
slies within the viewport plus that margin in screen px.
LongPressElapsed(double, double, double)
Whether a held press has reached the long-press threshold.
public static bool LongPressElapsed(double downTime, double now, double longPressSeconds)
Parameters
downTimedoublePress time in seconds (realtime).
nowdoubleCurrent time in seconds (realtime).
longPressSecondsdoubleHold duration in seconds that becomes LongPressed.
Returns
- bool
True when now minus downTime is at least longPressSeconds.
NeedsProjectionRefresh(MapViewTransform, MapViewTransform, bool, int, int, IElevationSampler, IElevationSampler)
Whether the shared projection cache must be recomputed for this view and store version.
public static bool NeedsProjectionRefresh(MapViewTransform view, MapViewTransform lastView, bool hasLastView, int storeVersion, int lastStoreVersion, IElevationSampler sampler, IElevationSampler lastSampler)
Parameters
viewMapViewTransformCurrent map view transform.
lastViewMapViewTransformView used when the cache was last filled.
hasLastViewboolFalse on the first call, when no prior fill exists.
storeVersionintCurrent spawn, despawn, or move generation.
lastStoreVersionintGeneration at the last fill.
samplerIElevationSamplerCurrent elevation sampler instance (Map's), or null for flat.
lastSamplerIElevationSamplerSampler instance the last fill resolved against.
Returns
- bool
True when the cache is empty, the view moved, a marker was added, removed, or moved, or the sampler instance itself swapped. The sampler is compared directly (not only through the view) because a surface-hosted view is deliberately built without a terrain argument and would otherwise never report a sampler swap.
PickAt(MapViewTransform, Ray, ScreenPoint, out double)
Prefab-tier pick at a ray and screen point: collider hit if the prefab has one, otherwise nearest projected-anchor within hover radius.
public WorldMarkerInstance PickAt(MapViewTransform view, Ray ray, ScreenPoint screen, out double distanceSq)
Parameters
viewMapViewTransformView whose projection the anchor fallback uses.
rayRayWorld ray to test against prefab colliders.
screenScreenPointCursor in top-left-origin screen px, matching MapViewTransform output.
distanceSqdouble0 for a collider hit or a miss; otherwise squared screen-px distance to the winning anchor.
Returns
- WorldMarkerInstance
The hit marker, or null.
ShouldEmitHover(int)
Whether HoverEntered and HoverExited may fire this frame.
public static bool ShouldEmitHover(int touchCount)
Parameters
touchCountintActive touch count; 0 means no touch.
Returns
- bool
True only when no touch is active, so a tap is not reported as a hover.
ShouldFireHoverEnter(WorldMarkerInstance, WorldMarkerInstance)
Whether HoverEntered should fire for this previous-to-current hover transition.
public static bool ShouldFireHoverEnter(WorldMarkerInstance previous, WorldMarkerInstance current)
Parameters
previousWorldMarkerInstanceMarker hovered last frame, or null.
currentWorldMarkerInstanceMarker hovered this frame, or null.
Returns
- bool
True when a marker is hovered that was not hovered last frame.
ShouldFireHoverExit(WorldMarkerInstance, WorldMarkerInstance)
Whether HoverExited should fire for this previous-to-current hover transition.
public static bool ShouldFireHoverExit(WorldMarkerInstance previous, WorldMarkerInstance current)
Parameters
previousWorldMarkerInstanceMarker hovered last frame, or null.
currentWorldMarkerInstanceMarker hovered this frame, or null.
Returns
- bool
True when a marker was hovered and the hover moved off it.
Spawn(GameObject, double, double, double, MarkerAltitudeMode)
Instantiates prefab as a prefab-tier marker at a geographic position.
public WorldMarkerInstance Spawn(GameObject prefab, double lat, double lon, double altitudeMeters, MarkerAltitudeMode altitudeMode = MarkerAltitudeMode.RelativeToGround)
Parameters
prefabGameObjectPrefab to instantiate; parented onto the table PrefabAnchor or this manager's Root.
latdoubleLatitude in degrees WGS84.
londoubleLongitude in degrees WGS84.
altitudeMetersdoubleAuthored altitude in meters; meaning depends on
altitudeMode.altitudeModeMarkerAltitudeModeHow
altitudeMetersis resolved against sampled ground. Default RelativeToGround.
Returns
- WorldMarkerInstance
Handle this manager repositions on every view change.
Remarks
This manager overwrites the spawned GameObject's transform every frame to keep it map-anchored. Do not drive its position or rotation with a Rigidbody or other physics motion; that motion is overwritten every frame by the reprojection.
TryGet(in MarkerRef, out WorldMarkerInstance)
Resolves a MarkerRef to the prefab instance it names.
public bool TryGet(in MarkerRef markerRef, out WorldMarkerInstance marker)
Parameters
markerRefMarkerRefCross-tier ref; must be Prefab and not none.
markerWorldMarkerInstanceThe live instance, or null when this returns false.
Returns
- bool
False when the ref is none, not Prefab, or stale.
TryGet(int, out WorldMarkerInstance)
Resolves a prefab handle from Id.
public bool TryGet(int handle, out WorldMarkerInstance marker)
Parameters
handleintSlot+generation id this manager handed out.
markerWorldMarkerInstanceThe live instance, or null when this returns false.
Returns
- bool
False when the id is stale after Despawn and reuse, or was never live here.
Events
Clicked
public event Action<WorldMarkerInstance> Clicked
Event Type
HoverEntered
public event Action<WorldMarkerInstance> HoverEntered
Event Type
HoverExited
public event Action<WorldMarkerInstance> HoverExited
Event Type
LongPressed
public event Action<WorldMarkerInstance> LongPressed