StaticCaveChunk
A class in Root.Township, Alta.Chunks.
A hand-built cave layer placed under a cave entrance by the CaveLayerManager. Positions itself under the entrance, links its culling portal, and on the server builds its pathfinding graph before the chunk finishes loading. Both sides.
- Listed in World, chunks and saving
- Inherits or implements
NetworkEntityBehaviour,ICaveLayer,IPortalApplier,IProceduralGenerationStreamer
Constructors
| Member | What it is |
|---|---|
StaticCaveChunk() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
11 private and internal fields
| Member | What it is |
|---|---|
private LocationChunk chunk | The location chunk this cave layer fills. |
private Transform entrance | Transform marking where the layer's entrance is. |
private Transform exit | Transform marking where the next layer joins on. |
private float height | How deep the layer is. Default 15. |
private bool isTerrainEnabled | Whether the terrain renderers are on. |
private static Logger logger | NLog logger for this class. |
private TaskCompletionSource<bool> pathfindingGenerated | Completes when the server finishes the A* scan. |
private CullingPortal portal | Culling portal between this layer and the one in front. |
private List<Renderer> staticRenderers | Renderers hidden while the local player isn't in the layer. |
private MethodSync syncSetup | Method sync for SyncSetup, also sent to each player on connect. |
private List<Renderer> terrain | Terrain renderers toggled with the local player. |
Properties
| Member | What it is |
|---|---|
Dictionary<Renderer, Vector3> AllStaticRenderers { get; set; } | Static renderers of the cave, with their positions. Client only; they are hidden while the local player is not in the chunk. |
LocationChunk Chunk { get; } | The location chunk for this cave layer. |
float Depth { get; private set; } | How deep below the surface this layer sits, set by SetEntrance. |
Vector2 Entrance { get; private set; } | The 2D (XZ) entrance point set by SetEntrance. |
Vector2 EntranceDirection { get; private set; } | The 2D (XZ) direction of the entrance. |
int LayerIdentifier { get; private set; } | This layer's number in the cave layer manager. |
CaveLayerManager Manager { get; private set; } | The cave layer manager that placed this layer. |
Transform PortalTransform { get; } | Transform of the cave's culling portal. |
Events
Methods
| Member | What it is |
|---|---|
string GetIdentifier(int layer) | Returns the chunk's identifier, whatever layer is asked for. |
override void Initialize() | Sets up the setup sync and, on clients, hides the cave's renderers until the local player is in the chunk. |
void InitializeCaveLayer(CaveLayerManager manager, int layer) | Stores the manager and layer number. |
override void OnConnected(Player player) | Server: sends this layer's position, rotation and layer number to the joining player. |
void RegisterPortal(LocationChunk chunk, ICaveLayer other) | Points the culling portal's front at the given chunk. |
void SetEntrance(float depth, Vector2 entrance, Vector2 direction) | Server: moves and rotates the layer so its entrance lines up, syncs it to clients, raises ExitReady and starts building pathfinding. |
void ToggleTerrain(bool isEnabled) | Shows or hides the cave terrain renderers. Always shown while the local player is in the chunk. |
11 private and internal methods
| Member | What it is |
|---|---|
private void ActivatePortal() | Makes this layer the chunk's portal applier, and the layer in front of its portal that one's applier. |
private void Awake() | Drops null entries from the static renderer list. |
private IEnumerator GeneratePathfinding() (iterator) | Server: coroutine that scans the cave A* graph over the chunk's bounds, then lets the chunk load go on. |
private void HandleLocalPlayer() | Client: records the static renderers and hides them and the terrain until the local player is in the chunk. |
private Task Alta.Chunks.IProceduralGenerationStreamer.LoadDynamic(bool hasGenerated) | Does nothing. |
private async Task Alta.Chunks.IProceduralGenerationStreamer.LoadStatic(CancellationToken cancellationToken) | Server: waits until the pathfinding is generated. Client: raises ClientLoadingFinished straight away. |
private void RecenterBounds() | Moves the chunk's bounds to sit under this layer, height deep. |
private void SyncSetup(IPlayer player, Stream stream) | Sends the layer index, manager and pose to clients, which then place the layer and register its portal. |
private void ToggleLocalPlayer(bool hasLocalPlayer) | Shows or hides the terrain and static renderers as the local player enters or leaves. |
private void Alta.Chunks.IProceduralGenerationStreamer.UnloadDynamic() | Does nothing. |
private void Alta.Chunks.IProceduralGenerationStreamer.UnloadStatic() | Does nothing. |