Skip to main content

NetworkAxisValue

An abstract class in Root.Township, Alta.Networking.

Base for a networked value along one axis (a slider, lever or hinge position). The server sends it compressed in a range; clients lerp to it, or snap when it's far off.

Constructors​

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

Fields​

MemberWhat it is
static AccumulativeAverageCount prepareForWriteTimerShared timing stats for preparing these values.
static AccumulativeAverageCount serializeTimerShared timing stats for serializing these values.
protected Transform TargetTransformThe transform the value moves.
10 private and internal fields
MemberWhat it is
private IUnityUpdateMethod fixedUpdateThe registered fixed update lerp, or null when not lerping.
private float fixedUpdateLerpTimeLerp factor per fixed update on clients; 1 or more means always snap.
private bool hasSyncedTrue once a value has been sent or received.
private bool isAlwaysSnappingTrue on the server or when lerping is off, so values are applied at once.
private bool isSnappingTrue while a snap is waiting for the end of receiving.
private Vector3 localAxisThe normalized axis the value is measured along.
private float precisionStep size used to pack the value.
private float snapThresholdDifference above which clients snap instead of lerping (-1 turns snapping off).
private float valueThe last synced value.
private float valueThresholdSmallest change that counts as worth sending or lerping.

Properties​

MemberWhat it is
protected abstract float CurrentValue { get; }Subclass: the value as it is now on this side.
protected Vector3 LocalAxis { get; }Local axis the value runs along.
protected abstract float MaximumValue { get; }Subclass: highest value, for compression.
protected abstract float MinimumValue { get; }Subclass: lowest value, for compression.
3 private and internal properties
MemberWhat it is
private int Alta.Networking.INetworkSerialized.MaximumBits { get; }Bits needed for the value at the set precision over the range.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; }Returns the shared prepareForWriteTimer.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; }Returns the shared serializeTimer.

Methods​

MemberWhat it is
override void Initialize()Client: registers a fixed update to smooth toward synced values. Snaps instead if the lerp time is 1 or more.
override void InitializeAsServer(SpawnData spawnData)Server: removes the smoothing update.
bool PrepareForWrite(bool isWriteFull)True if the value moved more than the threshold since the last send.
void Serialize(Stream stream, bool isWriteFull)Writes or reads the value. Clients snap after receiving if the gap is over the snap threshold, otherwise smooth.
void SetPositionLerp(float lerp)Server: sets the value as a 0 to 1 fraction of its range.
protected abstract void ApplyValue(float value)Subclass: sets the transform to a value.
protected abstract float GetDifference(float currentValue, float value)Subclass: gap between two values.
protected abstract float LerpToValue(float value, float lerpValue)Subclass: one smoothing step toward a value.
4 private and internal methods
MemberWhat it is
private void HandleRemote()Client fixed update: lerps toward the synced value, then sets it exactly and stops once close enough.
private void OnDisable()Stops the fixed update lerp.
private void OnEnable()Restarts the fixed update lerp if the entity is set up and not always snapping.
private void Snap()Applies the synced value straight away; runs at the end of receiving.