Loading...
Searching...
No Matches
CityBuilderCore.Building Class Reference

Detailed Description

Inheritance diagram for CityBuilderCore.Building:
CityBuilderCore.MessageReceiver CityBuilderCore.IBuilding CityBuilderCore.ISaveData CityBuilderCore.IStructure CityBuilderCore.ISaveData CityBuilderCore.IKeyed CityBuilderCore.ExpandableBuilding CityBuilderCore.Tests.DebugBuilding

Classes

class  BuildingAddonMetaData
 
class  BuildingComponentMetaData
 
class  BuildingData
 

Public Member Functions

virtual void Initialize ()
 initialization for buildings when placing and loading
is not called when a building is replaced
 
virtual void Setup ()
 only called when the building is first placed
 
Replace< T > (T prefab)
 replaces the building and all of its parts with another one
runtime values are transferred and references are reset to the new instances
 
void Move (Vector3 position, Quaternion rotation)
 moves the building to a different position
 
virtual void Terminate ()
 de-initializes the buildings and destroys it
 
bool HasBuildingPart< T > ()
 checks if a type of part(components, addons) exists
 
IEnumerable< T > GetBuildingParts< T > ()
 returns all parts composing the building(components, addons)
 
bool HasBuildingComponent< T > ()
 checks if a type of component exists
 
GetBuildingComponent< T > ()
 get first component of a certain type or null
 
IEnumerable< T > GetBuildingComponents< T > ()
 get all components of a certain type
 
bool HasBuildingAddon< T > ()
 checks if a type of addon exists
 
GetBuildingAddon< T > ()
 get first addon of a type or null
 
IEnumerable< T > GetBuildingAddons< T > ()
 get all addons of a certain type
 
AddAddon< T > (T prefab)
 adds and initializes an addon onto the building from a prefab
 
GetAddon< T > (string key)
 get the first addon with the specified key
 
void RemoveAddon (BuildingAddon addon)
 terminates and removes the addon from the building
 
bool RemoveAddon (string key)
 terminates and removes an addon from the building with the given key or returns false if none were found
 
virtual IEnumerable< Vector2Int > GetAccessPoints (PathType type, object tag)
 returns any access points that is accessible with the given pathtype
 
virtual ? Vector2Int GetAccessPoint (PathType type, object tag)
 returns the first access point that is accessible with the given pathtype
 
bool HasAccessPoint (PathType type, object tag=null)
 checks if the building can currently be accessed using the given pathtype
 
IEnumerable< Vector2Int > GetPoints ()
 retrieves all the points the structure occupies
 
bool HasPoint (Vector2Int position)
 checks if the structure occupies a certain point
 
virtual void Add (IEnumerable< Vector2Int > points)
 adds points to a structure, for example a tree to a tree structure collection
this may not be possible for structures with fixed points like buildings
typically called in a structures Start method
 
virtual void Remove (IEnumerable< Vector2Int > points)
 removes points from the structure, for some structures like buildings removing any point will remove the whole thing
typically called in a structures OnDestroy method
 
virtual string GetName ()
 retrieves the name of the structure for display in the UI
 
virtual string GetDescription ()
 display description
 
virtual void Suspend ()
 temporarily stops the building from working
 
virtual void Resume ()
 resumes work in the building after Suspend has been called
 
virtual string SaveData ()
 serializes the objects state(usually to json) and returns it
 
virtual void LoadData (string json)
 deserializes the serialized json data and loads the data as its new state
 
- Public Member Functions inherited from CityBuilderCore.MessageReceiver
virtual void OnMessages (string e)
 use when a single string has to be split into several messages
by default the parameter is split by spaces
 
virtual void OnMessage (string e)
 puts a message into the characters messaging pipeline
 

Public Attributes

BuildingInfo Info
 
Transform Pivot
 
- Public Attributes inherited from CityBuilderCore.MessageReceiver
MessageReceiver ForwardReceiver
 
UnityEvent< string > MessageReceived
 
MessageEvent[] MessageEvents
 

Protected Member Functions

virtual void Awake ()
 
virtual void Start ()
 
virtual void onReplacing (IBuilding replacement)
 
virtual void onMoving ()
 
virtual void onMoved (Vector2Int oldPoint, BuildingRotation oldRotation)
 
virtual IEnumerable< Vector2Int > getSpawnPoints ()
 

Protected Attributes

int _prefabIndex
 
Vector2Int? _point
 
Vector2Int? _size
 
BuildingRotation _rotation
 
Vector2Int? _accessPoint
 
Vector3? _worldCenter
 
IBuildingComponent[] _components
 
List< BuildingAddon_addonsQueue = new List<BuildingAddon>()
 
List< BuildingAddon_addons = new List<BuildingAddon>()
 

Properties

virtual Vector2Int RawSize [get]
 size of the building without rotation
 
virtual Vector2Int Point [get]
 origin(bottomLeft) point on the grid, stays constant when rotated
 
virtual Vector2Int Size [get]
 size on the grid, always positive
 
BuildingRotation Rotation [get]
 rotation of the building on the grid, just a int from 0 to 3
 
Vector2Int AccessPoint [get]
 
Vector3 WorldCenter [get]
 center position of the building in world space
 
virtual Vector3 PrimaryPosition [get]
 
virtual Vector3 SecondaryPosition [get]
 
StructureReference StructureReference [get, set]
 reference to the structure that keeps working even if the structure is replaced
 
BuildingReference BuildingReference [get, set]
 reference to the building that keeps working even if the building is replaced
 
string Key [get]
 unique identifier among a type of objects(might be used in savegames, be careful when changing)
 
bool IsDestructible [get]
 whether the structure can be removed by the player
 
bool IsMovable [get]
 whether the structure can be moved by the MoveTool
 
virtual bool IsDecorator [get]
 whether the structure is automatically removed when something is built on top of it
 
virtual bool IsWalkable [get]
 whether walkers can pass the points of this structure
 
Guid Id = Guid.NewGuid() [get, set]
 unique id for the building, used for saving is not carried over when replacing
 
bool IsSuspended [get]
 building is temporarly disabled, can be used to stop work in a building without having to destroy and rebuild
 
int Index [get, set]
 index of the prefab used, only relevant if the building has BuildingInfo.PrefabAlternatives
 
Transform Root [get]
 root transform used as a parent for things that belong to the building but should not be rotated in the pivot(walkers, bars)
 
float Efficiency [get]
 how efficient the building currently is, influenced by all parts implementing IEfficiencyFactor
ranges from 0-1, a building with half its employees would have 0.5 efficiency
 
bool IsWorking [get]
 whether a buildings efficiency is indisturbed
for example a farm on semi ideal land might not have full efficiency while still working
 
IBuildingComponent[] Components [get]
 
IReadOnlyCollection< BuildingAddonAddons [get]
 
- Properties inherited from CityBuilderCore.IBuilding
- Properties inherited from CityBuilderCore.IStructure
- Properties inherited from CityBuilderCore.IKeyed

Events

Action< PointsChanged< IStructure > > PointsChanged
 
Action< IBuilding, IBuildingReplacing
 
- Events inherited from CityBuilderCore.IStructure
Action< PointsChanged< IStructure > > PointsChanged
 has to be fired when a structures points changed so the manager can readjust paths
only viable for structures that are stored in list form like underlying, collections and tiles
other structures have to be reregistered
 

Member Function Documentation

◆ Add()

virtual void CityBuilderCore.Building.Add ( IEnumerable< Vector2Int > points)
inlinevirtual

adds points to a structure, for example a tree to a tree structure collection
this may not be possible for structures with fixed points like buildings
typically called in a structures Start method

Parameters
pointsthe points that will be added to the structure

Implements CityBuilderCore.IStructure.

◆ AddAddon< T >()

T CityBuilderCore.Building.AddAddon< T > ( T prefab)
inline

adds and initializes an addon onto the building from a prefab

Template Parameters
T
Parameters
prefab
Returns
the created addon instance

Implements CityBuilderCore.IBuilding.

Type Constraints
T :BuildingAddon 

◆ GetAccessPoint()

virtual ? Vector2Int CityBuilderCore.Building.GetAccessPoint ( PathType type,
object tag )
inlinevirtual

returns the first access point that is accessible with the given pathtype

Parameters
type
Returns

Implements CityBuilderCore.IBuilding.

Reimplemented in CityBuilderCore.Tests.DebugBuilding.

◆ GetAccessPoints()

virtual IEnumerable< Vector2Int > CityBuilderCore.Building.GetAccessPoints ( PathType type,
object tag )
inlinevirtual

returns any access points that is accessible with the given pathtype

Parameters
type
tag
Returns

Implements CityBuilderCore.IBuilding.

Reimplemented in CityBuilderCore.Tests.DebugBuilding.

◆ GetAddon< T >()

T CityBuilderCore.Building.GetAddon< T > ( string key)
inline

get the first addon with the specified key

Template Parameters
Ttype of addon to look for(BuildingAddon for any type)
Parameters
keykey of the addon to look for
Returns
a fitting addon or null if none were found

Implements CityBuilderCore.IBuilding.

Type Constraints
T :BuildingAddon 

◆ GetBuildingAddon< T >()

T CityBuilderCore.Building.GetBuildingAddon< T > ( )
inline

get first addon of a type or null

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :BuildingAddon 

◆ GetBuildingAddons< T >()

IEnumerable< T > CityBuilderCore.Building.GetBuildingAddons< T > ( )
inline

get all addons of a certain type

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :BuildingAddon 

◆ GetBuildingComponent< T >()

T CityBuilderCore.Building.GetBuildingComponent< T > ( )
inline

get first component of a certain type or null

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :class 
T :IBuildingComponent 

◆ GetBuildingComponents< T >()

IEnumerable< T > CityBuilderCore.Building.GetBuildingComponents< T > ( )
inline

get all components of a certain type

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :IBuildingComponent 

◆ GetBuildingParts< T >()

IEnumerable< T > CityBuilderCore.Building.GetBuildingParts< T > ( )
inline

returns all parts composing the building(components, addons)

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

◆ GetDescription()

virtual string CityBuilderCore.Building.GetDescription ( )
virtual

display description

Returns

Implements CityBuilderCore.IBuilding.

◆ GetName()

virtual string CityBuilderCore.Building.GetName ( )
virtual

retrieves the name of the structure for display in the UI

Returns
name of the structure for UI

Implements CityBuilderCore.IStructure.

◆ GetPoints()

IEnumerable< Vector2Int > CityBuilderCore.Building.GetPoints ( )
inline

retrieves all the points the structure occupies

Returns
the points the structure occupies

Implements CityBuilderCore.IStructure.

◆ HasAccessPoint()

bool CityBuilderCore.Building.HasAccessPoint ( PathType type,
object tag = null )

checks if the building can currently be accessed using the given pathtype

Parameters
type
Returns

Implements CityBuilderCore.IBuilding.

◆ HasBuildingAddon< T >()

bool CityBuilderCore.Building.HasBuildingAddon< T > ( )
inline

checks if a type of addon exists

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :BuildingAddon 

◆ HasBuildingComponent< T >()

bool CityBuilderCore.Building.HasBuildingComponent< T > ( )
inline

checks if a type of component exists

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :IBuildingComponent 

◆ HasBuildingPart< T >()

bool CityBuilderCore.Building.HasBuildingPart< T > ( )

checks if a type of part(components, addons) exists

Template Parameters
T
Returns

Implements CityBuilderCore.IBuilding.

◆ HasPoint()

bool CityBuilderCore.Building.HasPoint ( Vector2Int point)

checks if the structure occupies a certain point

Parameters
pointa point on the map
Returns
true if the structure occupies that point

Implements CityBuilderCore.IStructure.

◆ Initialize()

virtual void CityBuilderCore.Building.Initialize ( )
inlinevirtual

initialization for buildings when placing and loading
is not called when a building is replaced

Implements CityBuilderCore.IBuilding.

Reimplemented in CityBuilderCore.ExpandableBuilding, and CityBuilderCore.Tests.DebugBuilding.

◆ LoadData()

virtual void CityBuilderCore.Building.LoadData ( string json)
inlinevirtual

deserializes the serialized json data and loads the data as its new state

Parameters
json

Implements CityBuilderCore.ISaveData.

◆ Move()

void CityBuilderCore.Building.Move ( Vector3 position,
Quaternion rotation )
inline

moves the building to a different position

Implements CityBuilderCore.IBuilding.

◆ Remove()

virtual void CityBuilderCore.Building.Remove ( IEnumerable< Vector2Int > points)
inlinevirtual

removes points from the structure, for some structures like buildings removing any point will remove the whole thing
typically called in a structures OnDestroy method

Parameters
pointsthe points to remove

Implements CityBuilderCore.IStructure.

◆ RemoveAddon() [1/2]

void CityBuilderCore.Building.RemoveAddon ( BuildingAddon addon)
inline

terminates and removes the addon from the building

Parameters
addonthe addon instance to remove

Implements CityBuilderCore.IBuilding.

◆ RemoveAddon() [2/2]

bool CityBuilderCore.Building.RemoveAddon ( string key)
inline

terminates and removes an addon from the building with the given key or returns false if none were found

Parameters
key
Returns
true if an addon was found and removed

Implements CityBuilderCore.IBuilding.

◆ Replace< T >()

T CityBuilderCore.Building.Replace< T > ( T prefab)
inline

replaces the building and all of its parts with another one
runtime values are transferred and references are reset to the new instances

Template Parameters
T
Parameters
prefab
Returns

Implements CityBuilderCore.IBuilding.

Type Constraints
T :MonoBehaviour 
T :IBuilding 

◆ Resume()

virtual void CityBuilderCore.Building.Resume ( )
inlinevirtual

resumes work in the building after Suspend has been called

Implements CityBuilderCore.IBuilding.

◆ SaveData()

virtual string CityBuilderCore.Building.SaveData ( )
inlinevirtual

serializes the objects state(usually to json) and returns it

Returns
serialized save data

Implements CityBuilderCore.ISaveData.

Reimplemented in CityBuilderCore.ExpandableBuilding.

◆ Setup()

virtual void CityBuilderCore.Building.Setup ( )
inlinevirtual

only called when the building is first placed

Implements CityBuilderCore.IBuilding.

Reimplemented in CityBuilderCore.Tests.DebugBuilding.

◆ Suspend()

virtual void CityBuilderCore.Building.Suspend ( )
inlinevirtual

temporarily stops the building from working

Implements CityBuilderCore.IBuilding.

◆ Terminate()

virtual void CityBuilderCore.Building.Terminate ( )
inlinevirtual

de-initializes the buildings and destroys it

Implements CityBuilderCore.IBuilding.

Reimplemented in CityBuilderCore.Tests.DebugBuilding.

Property Documentation

◆ BuildingReference

BuildingReference CityBuilderCore.Building.BuildingReference
getset

reference to the building that keeps working even if the building is replaced

Implements CityBuilderCore.IBuilding.

◆ Efficiency

float CityBuilderCore.Building.Efficiency
get

how efficient the building currently is, influenced by all parts implementing IEfficiencyFactor
ranges from 0-1, a building with half its employees would have 0.5 efficiency

Implements CityBuilderCore.IBuilding.

◆ Id

Guid CityBuilderCore.Building.Id = Guid.NewGuid()
getset

unique id for the building, used for saving is not carried over when replacing

Implements CityBuilderCore.IBuilding.

◆ Index

int CityBuilderCore.Building.Index
getset

index of the prefab used, only relevant if the building has BuildingInfo.PrefabAlternatives

Implements CityBuilderCore.IBuilding.

◆ IsDecorator

virtual bool CityBuilderCore.Building.IsDecorator
get

whether the structure is automatically removed when something is built on top of it

Implements CityBuilderCore.IStructure.

◆ IsDestructible

bool CityBuilderCore.Building.IsDestructible
get

whether the structure can be removed by the player

Implements CityBuilderCore.IStructure.

◆ IsMovable

bool CityBuilderCore.Building.IsMovable
get

whether the structure can be moved by the MoveTool

Implements CityBuilderCore.IStructure.

◆ IsSuspended

bool CityBuilderCore.Building.IsSuspended
get

building is temporarly disabled, can be used to stop work in a building without having to destroy and rebuild

Implements CityBuilderCore.IBuilding.

◆ IsWalkable

virtual bool CityBuilderCore.Building.IsWalkable
get

whether walkers can pass the points of this structure

Implements CityBuilderCore.IStructure.

◆ IsWorking

bool CityBuilderCore.Building.IsWorking
get

whether a buildings efficiency is indisturbed
for example a farm on semi ideal land might not have full efficiency while still working

Implements CityBuilderCore.IBuilding.

◆ Key

string CityBuilderCore.Building.Key
get

unique identifier among a type of objects(might be used in savegames, be careful when changing)

Implements CityBuilderCore.IKeyed.

◆ Point

virtual Vector2Int CityBuilderCore.Building.Point
get

origin(bottomLeft) point on the grid, stays constant when rotated

Implements CityBuilderCore.IBuilding.

◆ RawSize

virtual Vector2Int CityBuilderCore.Building.RawSize
get

size of the building without rotation

Implements CityBuilderCore.IBuilding.

◆ Root

Transform CityBuilderCore.Building.Root
get

root transform used as a parent for things that belong to the building but should not be rotated in the pivot(walkers, bars)

Implements CityBuilderCore.IBuilding.

◆ Rotation

BuildingRotation CityBuilderCore.Building.Rotation
get

rotation of the building on the grid, just a int from 0 to 3

Implements CityBuilderCore.IBuilding.

◆ Size

virtual Vector2Int CityBuilderCore.Building.Size
get

size on the grid, always positive

Implements CityBuilderCore.IBuilding.

◆ StructureReference

StructureReference CityBuilderCore.Building.StructureReference
getset

reference to the structure that keeps working even if the structure is replaced

Implements CityBuilderCore.IStructure.

◆ WorldCenter

Vector3 CityBuilderCore.Building.WorldCenter
get

center position of the building in world space

Implements CityBuilderCore.IBuilding.