Skip to main content

CurveOutput

A class in Root.Township, the global namespace.

A networked looping timer that runs a value along an AnimationCurve and sends it to a FloatUnityEvent every frame. The server owns start, stop and reset and resyncs clients now and then; progress and running state are saved.

Constructors​

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

Fields​

10 private and internal fields
MemberWhat it is
private AltaCoroutine coroutineThe running UpdateTime coroutine.
private AnimationCurve curveCurve sampled with progress from 0 to 1.
private CurveOutputSaveData dataSaved state: progress and whether it is running.
private float magnitudeMultiplier on the curve value.
private FloatUnityEvent outputEvent that receives the value each frame.
private float speedLoops per second.
private MethodSync syncStart sync (also used for periodic resync).
private float syncIntervalServer: seconds between resyncs (60 by default).
private MethodSync syncResetReset sync.
private MethodSync syncStopStop sync.

Methods​

MemberWhat it is
override void Initialize()Sets up the start, stop and reset syncs; on clients it turns periodic resync off.
override void InitializeAsServer(SpawnData spawnData)Server: restarts the timer if the save says it was running.
override void OnConnected(Player player)Server: sends a joining player a start or stop sync with the current progress.
void ResetState()Server: if running, stops, sets progress to 0, outputs the start value and tells clients to reset.
void SetRunning(bool isRunning)Calls StartRunning or StopRunning. Handy as a UnityEvent target.
void StartRunning()Server: starts the timer if it isn't running and tells clients.
void StopRunning()Server: stops the timer if it is running and sends clients the progress it stopped at.
4 private and internal methods
MemberWhat it is
private void SyncReset(IPlayer player, Stream stream)Client: stops the timer, sets progress to 0 and outputs the start value.
private void SyncStart(IPlayer player, Stream stream)Client: reads the server's progress and restarts the timer from it.
private void SyncStop(IPlayer player, Stream stream)Client: reads the server's progress, stops the timer and outputs that value.
private IEnumerator UpdateTime() (iterator)Coroutine that outputs the curve value times magnitude each frame, advances progress by speed (wrapping at 1) and resyncs every syncInterval.