Skip to main content

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.

Constructors​

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

Fields​

11 private and internal fields
MemberWhat it is
private LocationChunk chunkThe location chunk this cave layer fills.
private Transform entranceTransform marking where the layer's entrance is.
private Transform exitTransform marking where the next layer joins on.
private float heightHow deep the layer is. Default 15.
private bool isTerrainEnabledWhether the terrain renderers are on.
private static Logger loggerNLog logger for this class.
private TaskCompletionSource<bool> pathfindingGeneratedCompletes when the server finishes the A* scan.
private CullingPortal portalCulling portal between this layer and the one in front.
private List<Renderer> staticRenderersRenderers hidden while the local player isn't in the layer.
private MethodSync syncSetupMethod sync for SyncSetup, also sent to each player on connect.
private List<Renderer> terrainTerrain renderers toggled with the local player.

Properties​

MemberWhat 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​

MemberWhat it is
event Action ClientLoadingFinishedClient: raised when the chunk's static content load step runs.
event Action<int, float, Vector2, Vector2> ExitReadyRaised after SetEntrance with the layer ID, the next layer's depth, and the exit position and direction.

Methods​

MemberWhat 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
MemberWhat 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.