Table of Contents

Class MapBoundsResolver

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Works out the world-space rectangle a scene's map covers.

public static class MapBoundsResolver
Inheritance
MapBoundsResolver
Inherited Members

Remarks

Three sources, most authoritative first: bounds authored on the WorldMapDefinition, the scene boundaries already baked into WorldSceneDetails, and — only in the editor, only while the scene is open — the live IBoundary components and terrains.

The middle source is why a scene needs no map authoring at all to get a working world map: every world scene is already required to have an IBoundary (the cache rebuild refuses a scene without one), and those boundaries are already harvested into the cache that the client loads. Deriving from them means the map matches the area the player is actually allowed to be in, which is a better default than any number typed by hand.

Methods

FromOpenScene()

The union of every IBoundary and Terrain in the currently loaded scenes.

public static Rect FromOpenScene()

Returns

Rect

The union rectangle, or UnityEngine.Rect.zero when nothing was found.

Remarks

Used by the map baker, which has the scene open and has not yet written a definition to derive from. Terrains are included as well as boundaries because a scene's terrain is what the bake camera will actually photograph — a boundary that crops tighter than the terrain would leave the map showing ground the rectangle claims is off the map.

FromSceneBoundaries(WorldSceneDetails)

The union of a scene's baked boundaries, on the XZ plane.

public static Rect FromSceneBoundaries(WorldSceneDetails details)

Parameters

details WorldSceneDetails

The scene's baked details. May be null.

Returns

Rect

The union rectangle, or UnityEngine.Rect.zero when there are no boundaries.

NormalizedToWorld(Rect, Vector2)

Converts normalised map coordinates back into a world position on the XZ plane.

public static Vector3 NormalizedToWorld(Rect rect, Vector2 normalized)

Parameters

rect Rect

The map rectangle, on the XZ plane.

normalized Vector2

Normalised coordinates, X and Y in 0..1.

Returns

Vector3

The world position, with Y left at zero.

Pad(Rect, float)

Grows a rectangle outwards by a fraction of its own size.

public static Rect Pad(Rect rect, float fraction)

Parameters

rect Rect

The rectangle to pad.

fraction float

Fraction of each axis to add on each side.

Returns

Rect

The padded rectangle.

Resolve(WorldMapDefinition, WorldSceneDetails)

The rectangle the map covers, on the XZ plane.

public static Rect Resolve(WorldMapDefinition definition, WorldSceneDetails details)

Parameters

definition WorldMapDefinition

The scene's map definition. May be null.

details WorldSceneDetails

The scene's baked details, used when no bounds are authored. May be null.

Returns

Rect

The map rectangle, or UnityEngine.Rect.zero when nothing could be derived.

WorldToNormalized(Rect, Vector3)

Converts a world position into normalised map coordinates.

public static Vector2 WorldToNormalized(Rect rect, Vector3 worldPosition)

Parameters

rect Rect

The map rectangle, on the XZ plane.

worldPosition Vector3

The world position to convert.

Returns

Vector2

X and Y in 0..1 across the rectangle, with Y running from the rectangle's minimum Z at zero. Values outside 0..1 mean the position is off the map; they are not clamped, because the caller usually needs to know by how much in order to clamp a marker to the correct edge.