LevelSelector
A class in Root.Township, Alta.Caves.
The dial on a level select cave teleporter. Turning it fills a gauge and picks a cave level, which LevelSelectCaveTeleporter listens for. The server owns the progress and syncs it.
- Listed in World generation
- Inherits or implements
NetworkEntityBehaviour,INetworkSerialized,IBuildRendererPostBake,IBuildBakeable
Constructors
| Member | What it is |
|---|---|
LevelSelector() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
static AccumulativeAverageCount prepareForWriteTimer | Shared timing stats for PrepareForWrite across all level selectors. |
static AccumulativeAverageCount serializeTimer | Shared timing stats for Serialize across all level selectors. |
15 private and internal fields
| Member | What it is |
|---|---|
private static readonly int _FillProgress | Shader property ID for the gauge fill amount. |
private Material animatingMaterial | Client copy of the gauge material that the fill is written to. |
private AnimationCurve animationProgress | Curve from dial progress to gauge fill. |
private RendererGroup baseRendererGroup | Renderer group the spawned pips' renderers are added to. |
private float currentProgress | Dial progress from 0 to 1. |
private Renderer[] gauges | Renderers that show the fill gauge. |
private bool isUpdating | True while the dial is being turned or easing, so it gets synced. |
private Transform lastPipPosition | Where the last pip goes. Pips are spread from pipParent to here. |
private Coroutine lerpToClosest | The running LerpToClosest coroutine, if any. |
private int levelCount | Backing field for LevelCount. |
private float linearDistance | How much turning (default 720) moves the progress from 0 to 1. |
private float minimumLinearProgress | Smallest turn amount the server acts on. Smaller amounts are ignored. |
private Transform pipParent | Parent transform of the pips, and the first pip's position. |
private CaveTeleporterPip pipPrefab | The CaveTeleporterPip prefab spawned for each level. |
private IntEvent updatedLevel | Event fired with the new level whenever the selected level changes. |
Properties
| Member | What it is |
|---|---|
int CurrentLevel { get; private set; } | The selected level, from 0 to LevelCount minus 1. Starts at -1 before any level is picked. |
int LevelCount { get; } | How many levels the dial can select (default 10). |
CaveTeleporterPip[] Pips { get; private set; } | The level marker pips spawned on clients. Null on a headless server. |
3 private and internal properties
| Member | What it is |
|---|---|
private int Alta.Networking.INetworkSerialized.MaximumBits { get; } | Bit budget declared for this component's network data (7). |
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; } | Returns the shared static prepareForWriteTimer. |
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; } | Returns the shared static serializeTimer. |
Methods
9 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Client: gives the gauges their own material copy and spawns the level pips. |
private IEnumerator LerpToClosest() (iterator) | Coroutine that moves the progress towards the current level's position, then stops marking the dial as updating. |
private void OnDrawGizmosSelected() | Editor: draws a line from the first pip position to the last. |
private void IBuildRendererPostBake.PostBake() | Removes null entries from gauges after the build bake. |
private bool Alta.Networking.INetworkSerialized.PrepareForWrite(bool isWriteFull) | Sends data only while the dial is being turned or easing to a level. |
private void Alta.Networking.INetworkSerialized.Serialize(Stream stream, bool isWriteFull) | Syncs progress and level. Clients update the gauge and selected pip when they read it. |
private void SpawnPips() | Spawns one pip per level, spaced evenly from the pip parent to lastPipPosition. |
private void UpdateLevel(int newLevel) | Changes the selected level, swaps which pip is lit on clients and fires updatedLevel. |
private void UpdateProgress() | Sets the gauge fill on clients. Server: rounds the progress to the nearest level and selects it. |
Used in
Members of other types that take, return or hold a LevelSelector: