Skip to main content

Domain

A class in Root.Township, ATT.Domains.

A private space for one player, spawned by DomainController below the map (y -200, spaced 400 apart). The micro tutorial uses one: the player's body is despawned and respawned inside, then returned to where they entered.

Constructors​

MemberWhat it is
Domain()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

7 private and internal fields
MemberWhat it is
private LocationChunk chunkBacking field for Chunk, the location chunk the domain's players spawn into.
private const float DefaultPlayerYSpawnOffsetHeight above the domain's position used for the default spawn point: 1.5 metres.
private IDomainController domainControllerDomain controller injected by VContainer, used by DestroyDomain.
private static readonly Logger loggerNLog logger for this class.
private NetworkPrefab networkPrefabBacking field for NetworkPrefab.
private readonly Dictionary<IPlayer, SpawnPoint> playerEntryPointsWhere each player was before entering, used by GetPlayerEntryPoint to send them back.
private SpawnPoint? spawnPointBacking field for SpawnPoint. When unset, the getter fills it from the domain's own position plus 1.5 metres up.

Properties​

MemberWhat it is
LocationChunk Chunk { get; }The domain's own location chunk, registered when the domain is created.
NetworkPrefab NetworkPrefab { get; }The domain's network prefab.
IPlayer Player { get; private set; }The player this domain belongs to.
SpawnPoint SpawnPoint { get; set; }Where players spawn inside the domain. Defaults to 1.5 m above the domain's origin.

Methods​

MemberWhat it is
async Task DestroyDomain()Asks the domain controller to destroy this domain.
SpawnPoint GetPlayerEntryPoint(IPlayer player)Where the player was before entering, to send them back. Falls back to a random respawn point and logs an error.
void Inject(IDomainController injectedDomainController)Dependency injection hook that receives the IDomainController.
void RegisterPlayerEntry(IPlayer player, SpawnPoint entryPoint)Records where a player entered from.
void SetPlayer(IPlayer player)Sets the owning player. Called by the domain controller.
void SetSpawnPoint(Transform reference)Sets where players spawn inside the domain from a transform.
async void SpawnPlayer(IPlayer iPlayer)Saves the player's current spot as their entry point, despawns their body and spawns a new one at the domain's spawn point.
2 private and internal methods
MemberWhat it is
private void DespawnPlayerController(Player player)Records where the player was as their entry point, saves them and destroys their controller. Uses Add, so a second entry for the same player throws.
private void MovePlayerToSpawnPoint()Moves the domain's Player (set by SetPlayer) to the spawn point and turns them to face its direction.

Used in​

Members of other types that take, return or hold a Domain: