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.
- Listed in Global namespace: M to O
- Inherits or implements
NetworkEntityBehaviour,INetworkSerialized,ISavable<NetworkedFloatStreamSaveData>,ISavableSave<NetworkedFloatStreamSaveData>,ISavableSaveBase - Derived types
NetworkedFloatStreamSaveData
Constructors
| Member | What it is |
|---|---|
NetworkedFloatStream() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
12 private and internal fields
| Member | What it is |
|---|---|
private int bits | Bits used to send the value between min and max. |
private FloatUnityEvent changed | Unity event fired when the value changes. |
private bool hasReceived | Whether a client has had its first value; the first one is applied at once. |
private bool isChanged | True when the value needs sending. |
private float max | Highest value. |
private float min | Lowest value. |
private static AccumulativeAverageCount prepareForWriteTimer | Shared timing stats for PrepareForWrite. |
private float remoteLerpPerSecond | If above 0, clients ease toward new values at this rate instead of snapping. |
private static AccumulativeAverageCount serializeTimer | Shared timing stats for Serialize. |
private float targetValue | Value a client is easing toward. |
private IUnityUpdateMethod update | Update handle while easing. |
private float value | Current value; also the starting value on the server. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
event Action<float> Changed | Fired when the value changes, on any side. |
Methods
| Member | What 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. |