LocationChunk
A class in Root.Township, Alta.Chunks.
A Chunk that is a place in the world, with bounds, neighbours, an environment and static scene content. Overworld tiles, caves and forest chunks are location chunks. Both sides; on clients ChunkWithLocalPlayer is the one you are standing in.
- Listed in World, chunks and saving
- Inherits or implements
Chunk - Derived types
CaveLayerChunk,OverworldChunk - Documented in Chunks
Constructors
| Member | What it is |
|---|---|
LocationChunk() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
ChunkEffect[] chunkEffects | Effects applied on clients when the local player enters or leaves the chunk. |
static Action<LocationChunk> OnChunkWithLocalPlayerChanged | Static callback run when the local player moves to another location chunk (null when cleared). |
21 private and internal fields
| Member | What it is |
|---|---|
private static HashSet<LocationChunk> allLocationChunks | Static set behind AllLocationChunks; chunks add themselves on Initialize and remove themselves on destroy. |
private List<string> androidNormalPointer | Content pointers loaded instead of normalPointer on Android. |
private Bounds bounds | Backing field for Bounds, the area the chunk covers. |
private Bounds bufferBounds | Bounds grown by BufferSize; backing field for BufferBounds. |
private Vector3 bufferBoundsMax | Top corner of bufferBounds; the upper limit when positions are serialized for this chunk. |
private Vector3 bufferBoundsMin | Bottom corner of bufferBounds; the lower limit when positions are serialized for this chunk. |
private const float BufferSize | How much (10 units) BufferBounds is larger than Bounds in total size. |
private ChunkRegion chunkRegion | Which region the chunk belongs to (overworld by default); can be changed with SetLocationDestination. |
private List<string> colliderOnlyPointer | Content pointers loaded on a headless server instead of the normal ones, probably the collider-only version of the static content. |
private ChunkConnections connections | Backing field for Connections: the chunk's links to its neighbours. |
private BasicEcosystem ecosystem | The BasicEcosystem on the same object, passed to the environment in Initialize. |
private ChunkEnvironment environment | Backing field for Environment; also supplies the chunk's SpawnData. |
private static bool hasSetLocationChunks | Set once GetLocationChunksInPlayMode has filled its cache. |
private bool isOverridingSafePosition | When set, the chunk the local player is in changes how the player's safe position is tracked; read through the static IsOverridingSafePosition. |
private bool isSkippingStaticContent | Backing field for IsSkippingStaticContent. |
private bool isUsingCustomLoadDistance | When set, loadDistance replaces the streaming settings' load radius for this chunk. |
private float loadDistance | Custom load radius (default 3) used when isUsingCustomLoadDistance is set. |
private static readonly Logger logger | NLog logger for this class. |
private List<string> normalPointer | Content pointers for the chunk's static content on non-Android clients. |
private ChunkPositions positions | Backing field for Positions; chunks with surfaces are also added to ContentLocationChunks. |
private int priority | Backing field for Priority; when chunks overlap, the chunk lookup picks the one with the highest priority. |
Properties
| Member | What it is |
|---|---|
static HashSet<LocationChunk> AllLocationChunks { get; } | Static set of every location chunk that has initialised. |
Bounds Bounds { get; set; } | The chunk's world space bounds. Setting it also updates BufferBounds. |
Bounds BufferBounds { get; } | Bounds grown by 10 units in size. Positions in this chunk are sent quantised to these bounds. |
virtual ChunkRegion ChunkRegion { get; } | Which region the chunk belongs to (overworld by default). |
static LocationChunk ChunkWithLocalPlayer { get; private set; } | Client: static, the location chunk the local player is currently in. |
List<string> ColliderOnlyPointer { get; } | Static content to load on a headless server: colliders only, no visuals. |
ChunkConnections Connections { get; } | Adjacent chunks and connection costs, used to decide which neighbours load around a player. |
static HashSet<LocationChunk> ContentLocationChunks { get; } | Static set of location chunks with spawn surfaces, used when picking a random chunk to spawn things in. |
float DynamicLoadStrength { get; } | Load budget for dynamic content around this chunk: its custom load distance or the streaming default, times the dynamic multiplier. |
ChunkEnvironment Environment { get; } | The chunk's environment settings, which also supply its SpawnData. |
bool HasLocalPlayer { get; private set; } | Client: true while the local player is inside this chunk. |
static bool IsOverridingSafePosition { get; } | Static, true when the local player's chunk has the override safe position flag. Then fall-recovery safe positions come from safe position setters instead of normal movement. |
static bool IsRecheckingChunks { get; set; } | Editor only: whether AllLocationChunks searches the scene again each time in edit mode. |
override bool IsSkippingStaticContent { get; } | Set on the prefab. When true the server skips this chunk's static content. |
List<string> NormalPointer { get; } | Static content to load on clients. A separate list is used on Android. |
ChunkMatrix OffsetMatrix { get; set; } | Transform from the prefab's original placement to where this chunk actually sits. Set by placed cave chunks and applied by the dynamic content manager. |
IPortalApplier PortalApplier { get; set; } | Cave portal handler that toggles terrain visibility for this chunk, if it is part of a cave. |
ChunkPositions Positions { get; } | Spawn surface definitions used to pick random spawn points in the chunk. |
int Priority { get; } | When several chunks contain a point, the one with the highest priority wins. |
override SpawnData SpawnData { get; } | Spawn data from the chunk's environment, so spawned content knows its biome. |
float StaticLoadStrength { get; } | Load budget for static content: custom load distance or the streaming default, times the static multiplier. |
Events
| Member | What it is |
|---|---|
event Action<bool> HasLocalPlayerChanged | Raised when the local player enters or leaves this chunk. Chunk effects hook it on clients. |
Methods
| Member | What it is |
|---|---|
static void ClearChunkWithLocalPlayer() | Client: clears ChunkWithLocalPlayer and tells that chunk the player left. |
virtual void GetNeighboursForLoading(float remainingLoadBudget, HashSet<Chunk> result) | Adds the neighbours that fit in the remaining load budget (minus each connection's cost) to the result set. |
virtual IEnumerable<LocationChunk> GetNeighboursForLookup() | The forced adjacent chunks, used when searching nearby chunks. |
void GetOverrideLoadDistance(out bool isUsingCustomLoadDistance, out float overrideLoadingDistance) | Reads whether a custom load distance is used and its value. |
override void Initialize() | Sets up environment and connections, hooks chunk effects on clients and adds itself to the static sets. |
void OnLocalPlayerChange(bool isContained) | Client: updates HasLocalPlayer and ChunkWithLocalPlayer, and raises the change events. |
virtual void PlayerEnteredChunk(Player player) | Hook run when a player moves into this chunk. Empty here; cave layer chunks override it. |
override void SerializePosition(Stream stream, ref Vector3 position, NetworkEntity entity = null) | Sends a position quantised to BufferBounds at 1 mm precision, so it must lie inside them. |
void SetLocationDestination(ChunkRegion newDestination) | Changes the chunk's ChunkRegion. |
void SetOverrideLoadDistance(float overrideLoadingDistance, bool isOverriding = true) | Turns on a custom load distance for this chunk with the given value. The second argument is ignored. |
protected override void OnDestroy() | Removes the chunk from the static sets. |
2 private and internal methods
| Member | What it is |
|---|---|
private static HashSet<LocationChunk> GetLocationChunksInEditMode() | Editor only: refills allLocationChunks with every LocationChunk in the scene when IsRecheckingChunks is set. |
private static HashSet<LocationChunk> GetLocationChunksInPlayMode() | Editor play mode: finds every LocationChunk once and caches the set. |
Used in
Members of other types that take, return or hold a LocationChunk:
CaveLayerManager.entranceChunk, CaveLayerChunk.GetNeighboursForLookup, CaveLayerStaticObject.TryGetCaveLayerStreamer, CaveLayerStreamer.chunk, CaveLayerStreamer.Chunk, CaveLayerStreamer.RegisterPortal, ChunkAdjacencyConfiguration.chunk, ChunkAdjacencyConfiguration.Chunk, ChunkAdjacencyConfiguration.ChunkAdjacencyConfiguration, ChunkConnections.AddAdjacent, ChunkConnections.Chunk, ChunkConnections.ConnectTwoWay, ChunkConnections.Initialize, ChunkEnvironment.Initialize, FastChunkLookup.DeregisterOtherChunk, FastChunkLookup.FastChunkLookup, FastChunkLookup.GetAllChunksByIndex, FastChunkLookup.GetAllChunksContainingPosition, FastChunkLookup.GetAllChunksIntersectingBounds, FastChunkLookup.GetBestChunk, FastChunkLookup.GetBestChunkContainingPosition, FastChunkLookup.GetBestChunkIntersectingBounds, FastChunkLookup.otherChunks, FastChunkLookup.RegisterOtherChunk, FastChunkLookup.RemoveOtherChunk, ICaveLayer.Chunk, ICaveLayer.RegisterPortal, LocationChunkHelper.DeregisterOtherChunk, LocationChunkHelper.GetAllContaining, LocationChunkHelper.GetBestContaining, LocationChunkHelper.GetChunksToLoad, LocationChunkHelper.GetChunkWeightingsForPosition, LocationChunkHelper.GetRandomChunkForPosition, LocationChunkHelper.RegisterOtherChunk, LocationChunkHelper.RemoveOtherChunk, LocationChunkHelper.SetupChunkLookup, StaticCaveChunk.chunk, StaticCaveChunk.Chunk, StaticCaveChunk.RegisterPortal, AtmosphereManager.EnsureAtmosphere, BorderDefinedAtmosphere.allChunks, CliffFill.GenerateInternal, CutoutPathEdgeFill.GenerateInternal, ForestBridges.ClearDynamic, ForestBridges.ClearStatic, ForestBridges.GenerateDynamic, ForestBridges.GenerateStatic, ForestEncounters.ClearDynamic, ForestEncounters.ClearStatic, ForestEncounters.GenerateDynamic, ForestEncounters.GenerateStatic, ForestFill.GenerateInternal, ForestFillCore.ClearDynamic, ForestFillCore.ClearStatic, ForestFillCore.GenerateDynamic, ForestFillCore.GenerateInternal, ForestFillCore.GenerateStatic, ForestGeneration.chunkEdges, ForestGeneration.chunkNodes, ForestGeneration.GetEdgesWithinChunk and 84 more.