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.
- Listed in Networking and servers
- Inherits or implements
NetworkEntityBehaviour,INetworkSerialized - Derived types
NetworkAxisPosition,NetworkAxisRotation
Constructors
| Member | What it is |
|---|---|
protected NetworkAxisValue() | 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 preparing these values. |
static AccumulativeAverageCount serializeTimer | Shared timing stats for serializing these values. |
protected Transform TargetTransform | The transform the value moves. |
10 private and internal fields
| Member | What it is |
|---|---|
private IUnityUpdateMethod fixedUpdate | The registered fixed update lerp, or null when not lerping. |
private float fixedUpdateLerpTime | Lerp factor per fixed update on clients; 1 or more means always snap. |
private bool hasSynced | True once a value has been sent or received. |
private bool isAlwaysSnapping | True on the server or when lerping is off, so values are applied at once. |
private bool isSnapping | True while a snap is waiting for the end of receiving. |
private Vector3 localAxis | The normalized axis the value is measured along. |
private float precision | Step size used to pack the value. |
private float snapThreshold | Difference above which clients snap instead of lerping (-1 turns snapping off). |
private float value | The last synced value. |
private float valueThreshold | Smallest change that counts as worth sending or lerping. |
Properties
3 private and internal properties
| Member | What 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
| Member | What 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. |