Class UITKMapView
The map itself: terrain image, fog of war, markers, and the chrome that sits over them. Used by both the minimap and the world map.
public class UITKMapView : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler
- Inheritance
-
CallbackEventHandlerFocusableVisualElementUITKMapView
- Implements
-
IEventHandlerIResolvedStyleITransformITransitionAnimationsIExperimentalFeaturesIVisualElementScheduler
- Inherited Members
-
VisualElement.disabledUssClassNameVisualElement.Focus()VisualElement.SendEvent(EventBase)VisualElement.MarkDirtyRepaint()VisualElement.IsMarkedForRepaint()VisualElement.ContainsPoint(Vector2)VisualElement.Overlaps(Rect)VisualElement.ToString()VisualElement.GetClasses()VisualElement.ClearClassList()VisualElement.FindAncestorUserData()VisualElement.SetBinding(BindingId, Binding)VisualElement.GetBinding(BindingId)VisualElement.TryGetBinding(BindingId, out Binding)VisualElement.GetBindingInfos()VisualElement.HasBinding(BindingId)VisualElement.ClearBinding(BindingId)VisualElement.ClearBindings()VisualElement.GetHierarchicalDataSourceContext()VisualElement.GetDataSourceContext(BindingId)VisualElement.TryGetDataSourceContext(BindingId, out DataSourceContext)VisualElement.TryGetLastBindingToUIResult(in BindingId, out BindingResult)VisualElement.TryGetLastBindingToSourceResult(in BindingId, out BindingResult)VisualElement.Add(VisualElement)VisualElement.Remove(VisualElement)VisualElement.Clear()VisualElement.IndexOf(VisualElement)VisualElement.Children()VisualElement.BringToFront()VisualElement.SendToBack()VisualElement.PlaceBehind(VisualElement)VisualElement.PlaceInFront(VisualElement)VisualElement.RemoveFromHierarchy()VisualElement.GetFirstOfType<T>()VisualElement.GetFirstAncestorOfType<T>()VisualElement.Contains(VisualElement)VisualElement.FindCommonAncestor(VisualElement)VisualElement.viewDataKeyVisualElement.userDataVisualElement.canGrabFocusVisualElement.focusControllerVisualElement.disablePlayModeTintVisualElement.usageHintsVisualElement.transformVisualElement.scaledPixelsPerPointVisualElement.layoutVisualElement.contentRectVisualElement.paddingRectVisualElement.worldBoundVisualElement.localBoundVisualElement.worldTransformVisualElement.hasActivePseudoStateVisualElement.hasInactivePseudoStateVisualElement.hasHoverPseudoStateVisualElement.hasCheckedPseudoStateVisualElement.hasEnabledPseudoStateVisualElement.hasDisabledPseudoStateVisualElement.hasFocusPseudoStateVisualElement.hasRootPseudoStateVisualElement.pickingModeVisualElement.nameVisualElement.enabledInHierarchyVisualElement.enabledSelfVisualElement.languageDirectionVisualElement.visibleVisualElement.generateVisualContentVisualElement.dataSourceVisualElement.dataSourcePathVisualElement.dataSourceTypeVisualElement.experimentalVisualElement.hierarchyVisualElement.cacheAsBitmapVisualElement.parentVisualElement.panelVisualElement.contentContainerVisualElement.visualTreeAssetSourceVisualElement.childCountVisualElement.scheduleVisualElement.styleVisualElement.resolvedStyleVisualElement.customStyleVisualElement.styleSheetsVisualElement.tooltipFocusable.Blur()Focusable.focusableFocusable.tabIndexFocusable.delegatesFocusCallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)CallbackEventHandler.RegisterCallbackOnce<TEventType>(EventCallback<TEventType>, TrickleDown)CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)CallbackEventHandler.RegisterCallbackOnce<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, CallbackOptions)CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, CallbackOptions)CallbackEventHandler.UnregisterAllRemovableCallbacks()CallbackEventHandler.HasTrickleDownHandlers()CallbackEventHandler.HasBubbleUpHandlers()CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)CallbackEventHandler.HandleEventBubbleUp(EventBase)CallbackEventHandler.HandleEventTrickleDown(EventBase)CallbackEventHandler.ExecuteDefaultAction(EventBase)CallbackEventHandler.NotifyPropertyChanged(in BindingId)
Remarks
One element, two panels. The minimap and the world map differ in size, in where their image comes from and in what the player may do to them, and in nothing else. Everything below — the world-to-view mapping, the fog overlay, marker placement, edge clamping — is identical, and a second copy of it is how a note pinned on the world map ends up a few metres from where it shows on the minimap.
Four stacked layers, not one drawing. Background, terrain, fog and markers are separate child elements rather than one UnityEngine.UIElements.VisualElement.generateVisualContent pass on this element, because generated content on a parent draws behind all of its children — so the terrain would have had to be a child anyway, and then the fog could not have been drawn over it. Layers also let each one choose how it draws: see below.
Why the terrain layer has two ways to draw and the fog only one. The live
minimap render texture is drawn as a plain background-image, because the camera has
already rotated and framed exactly what should be on screen — there is no texture-coordinate
work to do, and going through UI Toolkit's own path avoids the render-texture orientation
difference between graphics APIs (a render target is stored bottom-up under OpenGL and
top-down under D3D, Vulkan and Metal, so hand-written texture coordinates are upside down on
half the platforms the client ships to). The baked world map and the fog are windows into a
much larger image and need coordinates computed per corner, which a background image cannot
express, so those are generated meshes — and both are ordinary Texture2Ds, where the
orientation question does not arise.
Markers are real elements, not drawn into the mesh. They need labels, tooltips, hover states and clicks — everything UI Toolkit already does — and there are tens of them, not thousands. They are pooled rather than rebuilt, because a marker element recreated every refresh loses its hover state twice a second.
Constructors
UITKMapView()
Builds an empty view.
public UITKMapView()
Fields
MarkerClampedClass
USS class added to a marker that has been pinned to the frame edge.
public const string MarkerClampedClass = "map-marker--clamped"
Field Value
MarkerClass
USS class on each marker.
public const string MarkerClass = "map-marker"
Field Value
MarkerIconClass
USS class on a marker's icon.
public const string MarkerIconClass = "map-marker__icon"
Field Value
MarkerLabelClass
USS class on a marker's label.
public const string MarkerLabelClass = "map-marker__label"
Field Value
MarkerLayerClass
USS class on the layer that markers live in.
public const string MarkerLayerClass = "map-view__markers"
Field Value
MarkerTypeClassPrefix
USS class prefix for the marker type modifier, completed with the type name.
public const string MarkerTypeClassPrefix = "map-marker--"
Field Value
ViewClass
USS class on the root of the view.
public const string ViewClass = "map-view-surface"
Field Value
Properties
Fog
The explored map drawn over the terrain, or null for no fog.
public FogOfWarMap Fog { get; set; }
Property Value
FogColor
Colour of unexplored ground.
public Color FogColor { get; set; }
Property Value
- Color
MapBackground
Colour drawn behind the map image.
public Color MapBackground { get; set; }
Property Value
- Color
MapTexture
The terrain image drawn under everything. A live render texture, or a baked map.
public Texture MapTexture { get; set; }
Property Value
- Texture
MapTextureIsViewAligned
Whether MapTexture is a live render of exactly this view.
public bool MapTextureIsViewAligned { get; set; }
Property Value
MapTextureRect
The world rectangle MapTexture covers.
public Rect MapTextureRect { get; set; }
Property Value
- Rect
Remarks
Ignored when MapTextureIsViewAligned is set, because a live overhead render always covers exactly the view that produced it.
MapTint
Tint multiplied into the map image.
public Color MapTint { get; set; }
Property Value
- Color
View
The window this view is showing.
public MapViewTransform View { get; set; }
Property Value
Methods
LocalToWorld(Vector2)
Converts a point inside this element into a world position.
public Vector3 LocalToWorld(Vector2 localPosition)
Parameters
localPositionVector2The point in the element's own coordinate space.
Returns
- Vector3
The world position on the XZ plane.
RefreshSurface()
Redraws the terrain and fog layers without touching the markers.
public void RefreshSurface()
Remarks
Called after every overhead render. A render texture assigned as a background image does not by itself mark anything dirty, so a minimap between marker refreshes would show the last frame UI Toolkit happened to repaint rather than the one just rendered.
RelayoutMarkers()
Re-places the markers already collected, for the current View.
public void RelayoutMarkers()
Remarks
Split from SetMarkers(List<MapMarkerSnapshot>) because the two costs are wildly different and want wildly different rates. Collecting the markers walks the whole registry, resolves a relationship per marker and applies the visibility rules; placing them writes two style values per element. Collecting ten times a second is plenty — a creature crosses about two pixels of a minimap in that time — but the view itself moves every single frame with the player, so placing at the collection rate leaves every marker pinned to where the map used to be for a tenth of a second, which reads as the terrain sliding out from under the icons.
ReleaseMarkers()
Releases the marker elements back to the pool.
public void ReleaseMarkers()
Remarks
Called when a panel's visual tree is rebuilt. UI Toolkit hands a document a fresh root on every enable, so a view holding elements from the previous tree would keep adding them to a parent nobody draws.
SetMarkers(List<MapMarkerSnapshot>)
Replaces what the view draws and lays it out again.
public void SetMarkers(List<MapMarkerSnapshot> markers)
Parameters
markersList<MapMarkerSnapshot>The markers to draw. Copied, not retained.
Remarks
Copied because the caller reuses its list every refresh; holding the caller's list would mean the view's contents changed underneath it between a refresh and the layout pass that acts on it.
WorldToLocal(Vector3)
Converts a world position into a point inside this element.
public Vector2 WorldToLocal(Vector3 worldPosition)
Parameters
worldPositionVector3The world position.
Returns
- Vector2
The point in the element's own coordinate space.
Events
OnMapClicked
Raised when the player clicks the map without dragging it, with the world position they clicked and the marker nearest to it, when one was close enough to count.
public event Action<Vector3, MapMarkerSnapshot?> OnMapClicked
Event Type
- Action<Vector3, MapMarkerSnapshot?>
OnMapScrolled
Raised when the player scrolls over the map, with the scroll delta.
public event Action<float> OnMapScrolled