Skip to main content

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.

Constructors​

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

Fields​

MemberWhat it is
static AccumulativeAverageCount prepareForWriteTimerShared timing stats for PrepareForWrite across all level selectors.
static AccumulativeAverageCount serializeTimerShared timing stats for Serialize across all level selectors.
15 private and internal fields
MemberWhat it is
private static readonly int _FillProgressShader property ID for the gauge fill amount.
private Material animatingMaterialClient copy of the gauge material that the fill is written to.
private AnimationCurve animationProgressCurve from dial progress to gauge fill.
private RendererGroup baseRendererGroupRenderer group the spawned pips' renderers are added to.
private float currentProgressDial progress from 0 to 1.
private Renderer[] gaugesRenderers that show the fill gauge.
private bool isUpdatingTrue while the dial is being turned or easing, so it gets synced.
private Transform lastPipPositionWhere the last pip goes. Pips are spread from pipParent to here.
private Coroutine lerpToClosestThe running LerpToClosest coroutine, if any.
private int levelCountBacking field for LevelCount.
private float linearDistanceHow much turning (default 720) moves the progress from 0 to 1.
private float minimumLinearProgressSmallest turn amount the server acts on. Smaller amounts are ignored.
private Transform pipParentParent transform of the pips, and the first pip's position.
private CaveTeleporterPip pipPrefabThe CaveTeleporterPip prefab spawned for each level.
private IntEvent updatedLevelEvent fired with the new level whenever the selected level changes.

Properties​

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

MemberWhat it is
void FinishRotation()Starts easing the progress to the exact position of the current level.
override void Initialize()Server: works out the starting level from the current progress.
void Progress(float linearProgress)Turns the dial by the given amount. Server: moves the progress if the amount is above the minimum and updates the level.
9 private and internal methods
MemberWhat 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: