CaveLayerStreamer
A class in Root.Township, Alta.Chunks.
Streams one procedurally generated cave layer as its own location chunk below the surface. The CaveLayerManager places it at its entrance; it spawns the layer's generator content, positions the culling portal and syncs the layout to clients.
- Listed in World, chunks and saving
- Inherits or implements
NetworkEntityBehaviour,ISavable<CaveLayerStreamerSaveData>,ISavableSave<CaveLayerStreamerSaveData>,ISavableSaveBase,ICaveLayer,IPortalApplier,IProceduralGenerationStreamer - Derived types
CaveLayerStreamerSaveData - Documented in Caves
Constructors
| Member | What it is |
|---|---|
CaveLayerStreamer() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
const int MaxNumberOfLayers | Upper bound used when syncing the layer number. |
22 private and internal fields
| Member | What it is |
|---|---|
private Material androidTerrainMaterial | Terrain material used on Android while the local player is in the layer. |
private Material androidTerrainMaterialLOD1 | Cheaper terrain material used on Android while the local player is elsewhere. |
private LocationChunk chunk | Backing field for Chunk. |
private Vector3 chunkBoundsExtents | Half size of the layer chunk's bounds, which sit below the layer's position. 200 by 7.5 by 200 by default. |
private Ecosystem ecosystem | Backing field for Ecosystem. |
private Vector2 entranceDirection | Backing field for EntranceDirection. |
private GenerationBase generator | Cache for Generator. |
private bool isConnect | True only while sending the setup to a joining player. |
private bool isGenerated | Whether the layer has been generated before. Saved; first generation sets IsGeneratingDynamic on the server. |
private int layer | Backing field for LayerIdentifier. |
private float layerContentOffset | Local Y of the spawned layer content. -7.5 by default. |
private NetworkEntity layerEntity | The spawned layer content entity (not saved). Null when unloaded. |
private bool loaded | True once Generate has spawned the content, so it runs only once per load. |
private static Logger logger | NLog logger for this class. |
private RecastGraph navGraph | The A* recast graph for this layer. Null until GeneratePathfinding builds it. |
private bool needsMatrix | Always true, so the world to local matrix is worked out on every renderer register call. |
private ICaveLayer neighborStreamer | The cave layer in front of the portal (the one above). |
private CullingPortal portal | The culling portal between this layer and the one above. Backs PortalTransform. |
private MethodSync syncLayer | Method sync for the manager and layer number, sent to joining players. |
private MethodSyncStruct<Vector3> syncLayerSetup | Method sync for the layer position and portal pose. Sent on generate and to joining players. |
private Renderer terrainRenderer | The layer's terrain renderer, set by RegisterTerrainRenderer. |
private Matrix4x4 worldToLocal | The streamer's world to local matrix, used to pick renderers in the layer's height band. |
Properties
| Member | What it is |
|---|---|
Dictionary<Renderer, Vector3> AllStaticRenderers { get; } | Static renderers in the layer's band, with their positions. Clients only; shown only while the local player is in the chunk. |
Bounds Bounds { get; set; } | Bounds used for the layer's pathfinding graph. |
LocationChunk Chunk { get; private set; } | The location chunk on the same object. |
float Depth { get; set; } | Depth of the layer below the manager. Set with SetEntrance. |
Ecosystem Ecosystem { get; } | Ecosystem asset for this layer. |
Vector2 Entrance { get; set; } | Horizontal position of the layer's entrance. |
Vector2 EntranceDirection { get; } | Horizontal direction the entrance faces. |
GenerationBase Generator { get; } | The generation component in the spawned layer content, or null before Generate. |
bool IsGeneratingDynamic { get; private set; } | True on the server when the layer is being generated for the first time. |
int LayerIdentifier { get; } | The layer number. |
CaveLayerManager Manager { get; private set; } | The cave layer manager that owns this layer. |
bool NeedToGeneratePathFinding { get; } | True until the pathfinding graph has been built. |
Transform PortalTransform { get; private set; } | Transform of the culling portal between this layer and the one above. |
Events
Methods
| Member | What it is |
|---|---|
void DeregisterRenderers(Renderer[] renderers) | Removes renderers from AllStaticRenderers. Does nothing on a headless server. |
async Task Generate() | Spawns the layer content prefab once, positions the portal, syncs setup to clients and runs the generator. |
IEnumerator GeneratePathfinding() (iterator) | Coroutine that scans an A* graph over the layer's bounds, if not already built. |
string GetIdentifier(int layer) | Returns the chunk identifier for a layer number, such as "Cave Layer 2". |
override void Initialize() | Sets up the network messages for the layer number and layout. |
void InitializeCaveLayer(CaveLayerManager manager, int layerId) | Links the streamer to its manager and layer number and sets the chunk's bounds and identifier. |
void OnClientLoadingFinished() | Raises ClientLoadingFinished. |
override void OnConnected(Player player) | Server: sends the layer number and layout to a joining player. |
void OnExitReady(Vector2 exit, Vector2 exitDirection) | Called by the generator when the exit is placed; raises ExitReady for the layer below. |
void RegisterPortal(LocationChunk chunk, ICaveLayer other) | Links the portal to the chunk in front of it and its cave layer. |
void RegisterRenderers(Renderer[] renderers) | Adds renderers that sit in the layer's vertical band to AllStaticRenderers. Does nothing on a headless server. |
void RegisterTerrainRenderer(Renderer renderer) | Stores the layer's terrain renderer and sets its visibility and Android material. |
void SetEntrance(float depth, Vector2 entrance, Vector2 direction) | Moves the layer to the given depth and entrance and recentres its bounds. |
void SetGeneratorChunk() | Puts the spawned layer content into this layer's chunk. |
void ToggleTerrain(bool isToRenderTerrain) | Shows or hides the terrain renderer; always shown while the local player is in the chunk. |
14 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Finds the LocationChunk on the same object and caches the portal's transform. |
private void FinishPositionPortal() | Finds the chunk in front of the portal and makes this layer (and that neighbour) the chunks' portal applier. |
private void HandleLocalPlayer() | Clients: hooks the chunk's local player and fully unloaded events. Called one frame after Initialize. |
private async Task Alta.Chunks.IProceduralGenerationStreamer.LoadDynamic(bool hasGenerated) | Marks the layer generated, waits for its entrance from the manager, then runs Generate. First generation only spawns dynamic content on the server. |
private Task Alta.Chunks.IProceduralGenerationStreamer.LoadStatic(CancellationToken cancellationToken) | Does nothing; the layer has no static stage. |
private void OnDrawGizmos() | Editor: draws the entrance direction and the portal's up from the portal. |
private void PositionPortal() | Moves the portal to the entrance, facing down and along the entrance direction. |
private void RecenterBounds(Vector3 boundsCenter) | Moves the chunk's bounds to a new centre. |
private void SyncLayer(IPlayer player, Stream stream) | Method sync handler for the manager and layer number. Clients run InitializeCaveLayer and register in the manager. |
private void SyncLayerSetup(IPlayer player, Stream stream, Vector3 position) | Method sync handler for the layer position, entrance direction and portal pose. Clients set up bounds and the portal from it. |
private void ToggleLocalPlayer(bool hasLocalPlayer) | Clients: shows the terrain and static renderers only while the local player is in the chunk, swapping Android LOD materials. |
private void Alta.Chunks.IProceduralGenerationStreamer.UnloadDynamic() | Despawns the layer content through the manager and forgets the generator. |
private void Unloaded(Chunk chunk) | Clears AllStaticRenderers when the chunk fully unloads. |
private void Alta.Chunks.IProceduralGenerationStreamer.UnloadStatic() | Clears AllStaticRenderers. |
Used in
Members of other types that take, return or hold a CaveLayerStreamer:
GenerationBase.LayerStreamer, GenerationBase.SetupLayer, IGenerator.LayerStreamer, CaveLayerStaticObject.streamer, CaveLayerStaticObject.TryGetCaveLayerStreamer, Ecosystem.streamer, CullingPortal.backStreamer, CullingPortal.frontStreamer, CullingPortal.SetChunk, CullingPortal.SetupChunkReference, CullingPortal.CullingSide.CullingSide, CullingPortal.CullingSide.streamer, InGameInspector.MineStairsPointer.currentStreamer.