Loading...
Searching...
No Matches
CityBuilderCore.MapBase Class Referenceabstract

Detailed Description

base class for maps that provides overridable default implementations for all the grid handling
which points on the map can be walked or built upon is up to the concrete map implementation that inherits from this base

https://citybuilder.softleitner.com/manual

Inheritance diagram for CityBuilderCore.MapBase:
CityBuilderCore.IMap CityBuilderCore.IGridOverlay CityBuilderCore.IGridPositions CityBuilderCore.IGridRotations CityBuilderCore.DefaultMap CityBuilderCore.HexagonMap CityBuilderCore.IsometricMap CityBuilderCore.TerrainMap

Public Types

enum  RotationMode { Rotate , Mirror , MirrorAndFlip , Disabled }
 

Public Member Functions

bool IsInside (Vector2Int position)
 checks if a point is inside the map size
 
bool IsBuildable (Vector2Int position, int mask, object tag=null)
 checks if a point is ok to build on or if the map somehow blocks building there
 
bool IsWalkable (Vector2Int position)
 check if a point can be walked on and may be used in pathfinding
 
bool CheckGround (Vector2Int position, Object[] options)
 checks the ground for certain features
for example in tilemap base maps this would be a tile
 
void Show ()
 shows grid lines on the map
 
void Hide ()
 hides grid lines on the map
 
virtual Vector3 ClampPosition (Vector3 position)
 clamps a position to be inside the maps size
if, for example, a position 5,-10 is passed for a map that starts at 0,0 the position will be clamped to 5,0
 
virtual Vector2Int ClampPoint (Vector2Int point)
 clamps a point to be inside the maps size
 
virtual Vector2Int GetGridPosition (Vector3 position)
 turns a world position into a map point
 
virtual Vector3 GetWorldPosition (Vector2Int position)
 turns a map point into the world position in its lower corner
 
virtual Vector3 GetCenterFromPosition (Vector3 position)
 calculates the cells center from its corner position
to get the cell center from any position in it use Extensions.GetWorldCenterPosition(IGridPositions, Vector3)
 
virtual Vector3 GetPositionFromCenter (Vector3 center)
 calculates the cells corner position from its center
 
virtual Vector3 GetVariance ()
 get position variance for walkers and such, can be used so walkers on the same point dont overlap
 
virtual void SetRotation (Transform transform, Vector3 direction)
 adjusts a transform in order to visually reflect the direction it is facing
 
virtual void SetRotation (Transform transform, float rotation)
 adjusts a transform by a rotation in degrees
 
virtual float GetRotation (Vector3 direction)
 calculates a numeric rotation in degrees from a direction
 
virtual Vector3 GetDirection (float angle)
 calculates a direction from a numeric roation
 

Public Attributes

Vector2Int Size
 
Renderer GridVisual
 
float Variance
 
RotationMode Rotation
 

Protected Member Functions

virtual void Awake ()
 
virtual void Start ()
 
virtual void OnDrawGizmos ()
 

Properties

virtual bool IsHex [get]
 whether we're on a hexagonal map which may need some special handling
 
virtual bool IsXY [get]
 whether the map grid is in xy, usually in 2d games
3d games often use Y as the height axis and have their grid in XZ
 
virtual Vector3 CellOffset [get]
 delta position from one cell to the next
 
virtual Vector3 WorldCenter [get]
 world position at the center of the map
 
virtual Vector3 WorldSize [get]
 
Grid Grid [get]
 
- Properties inherited from CityBuilderCore.IMap

Member Function Documentation

◆ CheckGround()

bool CityBuilderCore.MapBase.CheckGround ( Vector2Int point,
Object[] options )
abstract

checks the ground for certain features
for example in tilemap base maps this would be a tile

Parameters
pointthe point on the map to check
optionsa set of features that would be acceptable
Returns
true if the ground exhibits one of the features

Implements CityBuilderCore.IMap.

◆ ClampPoint()

virtual Vector2Int CityBuilderCore.MapBase.ClampPoint ( Vector2Int point)
inlinevirtual

clamps a point to be inside the maps size

Parameters
pointa point that may or may not be inside the map
Returns
a point inside the map

Implements CityBuilderCore.IMap.

◆ ClampPosition()

virtual Vector3 CityBuilderCore.MapBase.ClampPosition ( Vector3 position)
inlinevirtual

clamps a position to be inside the maps size
if, for example, a position 5,-10 is passed for a map that starts at 0,0 the position will be clamped to 5,0

Parameters
positionthe position to check
Returns
the clamped position

Implements CityBuilderCore.IMap.

Reimplemented in CityBuilderCore.HexagonMap, and CityBuilderCore.IsometricMap.

◆ GetCenterFromPosition()

virtual Vector3 CityBuilderCore.MapBase.GetCenterFromPosition ( Vector3 position)
inlinevirtual

calculates the cells center from its corner position
to get the cell center from any position in it use Extensions.GetWorldCenterPosition(IGridPositions, Vector3)

Parameters
positionabsolute world space position of the cell cornder
Returns
center of the cell in absolute world space

Implements CityBuilderCore.IGridPositions.

Reimplemented in CityBuilderCore.IsometricMap.

◆ GetDirection()

virtual Vector3 CityBuilderCore.MapBase.GetDirection ( float angle)
inlinevirtual

calculates a direction from a numeric roation

Parameters
anglerotation indegrees
Returns
direction the angle is facing

Implements CityBuilderCore.IGridRotations.

◆ GetGridPosition()

virtual Vector2Int CityBuilderCore.MapBase.GetGridPosition ( Vector3 position)
inlinevirtual

turns a world position into a map point

Parameters
positionabsolute world space position(transform.position)
Returns
map point of the cell the position was inside

Implements CityBuilderCore.IGridPositions.

◆ GetPositionFromCenter()

virtual Vector3 CityBuilderCore.MapBase.GetPositionFromCenter ( Vector3 center)
inlinevirtual

calculates the cells corner position from its center

Parameters
centerabsolute world space position of the cell center
Returns
corner of the cell in absolute world space

Implements CityBuilderCore.IGridPositions.

Reimplemented in CityBuilderCore.IsometricMap.

◆ GetRotation()

virtual float CityBuilderCore.MapBase.GetRotation ( Vector3 direction)
inlinevirtual

calculates a numeric rotation in degrees from a direction

Parameters
directiondirection the object is facing
Returns
rotation in degrees

Implements CityBuilderCore.IGridRotations.

◆ GetVariance()

virtual Vector3 CityBuilderCore.MapBase.GetVariance ( )
inlinevirtual

get position variance for walkers and such, can be used so walkers on the same point dont overlap

Returns

Implements CityBuilderCore.IMap.

Reimplemented in CityBuilderCore.IsometricMap.

◆ GetWorldPosition()

virtual Vector3 CityBuilderCore.MapBase.GetWorldPosition ( Vector2Int point)
inlinevirtual

turns a map point into the world position in its lower corner

Parameters
pointmap/cell point
Returns
absolute world position in the corner of the cell

Implements CityBuilderCore.IGridPositions.

◆ Hide()

void CityBuilderCore.MapBase.Hide ( )

hides grid lines on the map

Implements CityBuilderCore.IGridOverlay.

◆ IsBuildable()

bool CityBuilderCore.MapBase.IsBuildable ( Vector2Int point,
int mask,
object tag = null )
abstract

checks if a point is ok to build on or if the map somehow blocks building there

Parameters
pointthe point on the map to check
maskthe structure levels to check, 0 for all
Returns

Implements CityBuilderCore.IMap.

◆ IsInside()

bool CityBuilderCore.MapBase.IsInside ( Vector2Int point)
inline

checks if a point is inside the map size

Parameters
pointthe point to check
Returns
true if the point is inside the map

Implements CityBuilderCore.IMap.

◆ IsWalkable()

bool CityBuilderCore.MapBase.IsWalkable ( Vector2Int point)
abstract

check if a point can be walked on and may be used in pathfinding

Parameters
pointthe point to check
Returns
true if the point allows walkers to pass

Implements CityBuilderCore.IMap.

◆ SetRotation() [1/2]

virtual void CityBuilderCore.MapBase.SetRotation ( Transform transform,
float rotation )
inlinevirtual

adjusts a transform by a rotation in degrees

Parameters
transformthe transform that will be chaned
rotationthe rotation in degrees

Implements CityBuilderCore.IGridRotations.

◆ SetRotation() [2/2]

virtual void CityBuilderCore.MapBase.SetRotation ( Transform transform,
Vector3 direction )
inlinevirtual

adjusts a transform in order to visually reflect the direction it is facing

Parameters
transformthe transform that will be changed
directionthe direction the entity moves or looks at

Implements CityBuilderCore.IGridRotations.

◆ Show()

void CityBuilderCore.MapBase.Show ( )

shows grid lines on the map

Implements CityBuilderCore.IGridOverlay.

Property Documentation

◆ CellOffset

virtual Vector3 CityBuilderCore.MapBase.CellOffset
get

delta position from one cell to the next

Implements CityBuilderCore.IMap.

◆ IsHex

virtual bool CityBuilderCore.MapBase.IsHex
get

whether we're on a hexagonal map which may need some special handling

Implements CityBuilderCore.IMap.

◆ IsXY

virtual bool CityBuilderCore.MapBase.IsXY
get

whether the map grid is in xy, usually in 2d games
3d games often use Y as the height axis and have their grid in XZ

Implements CityBuilderCore.IMap.

◆ WorldCenter

virtual Vector3 CityBuilderCore.MapBase.WorldCenter
get

world position at the center of the map

Implements CityBuilderCore.IMap.