Skip to main content

NetworkedFloatStream

A class in Root.Township, the global namespace.

Component holding one float between a min and max. The server sets it and it reaches clients in the regular entity stream using a set number of bits. Saved with the entity.

Constructors​

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

Fields​

12 private and internal fields
MemberWhat it is
private int bitsBits used to send the value between min and max.
private FloatUnityEvent changedUnity event fired when the value changes.
private bool hasReceivedWhether a client has had its first value; the first one is applied at once.
private bool isChangedTrue when the value needs sending.
private float maxHighest value.
private float minLowest value.
private static AccumulativeAverageCount prepareForWriteTimerShared timing stats for PrepareForWrite.
private float remoteLerpPerSecondIf above 0, clients ease toward new values at this rate instead of snapping.
private static AccumulativeAverageCount serializeTimerShared timing stats for Serialize.
private float targetValueValue a client is easing toward.
private IUnityUpdateMethod updateUpdate handle while easing.
private float valueCurrent value; also the starting value on the server.

Properties​

MemberWhat it is
int MaximumBits { get; }Bits used to send the value (2 to 32).
AccumulativeAverageCount PrepareForWriteTimer { get; }Shared profiling timer.
AccumulativeAverageCount SerializeTimer { get; }Shared profiling timer.
float Value { get; }Current value.

Events​

MemberWhat it is
event Action<float> ChangedFired when the value changes, on any side.

Methods​

MemberWhat it is
override void InitializeAsServer(SpawnData spawnData)Server: reapplies the starting value so change events fire.
void ModifyValue(float delta)Server: adds to the value, clamped.
bool PrepareForWrite(bool isWriteFull)True once after the value changes, so it is only sent when needed.
void Serialize(Stream stream, bool isWriteFull)Writes or reads the value. On clients it can lerp to the new value if remoteLerpPerSecond is set.
void SetValue(float value)Server only: sets the value, clamped to min and max. Does nothing on clients.
3 private and internal methods
MemberWhat it is
private void OnDestroy()Stops the remote lerp update.
private void RemoteUpdate()Client: eases the value toward the last received one each frame, then stops.
private void SetValueInternal(float value)Sets the value, marks it for sending and fires both change events if it changed.