Skip to main content

SimpleNetworkedPivot

A class in Root.Township, the global namespace.

Syncs one rotation axis of a hinged part (a pivot driven by a pickup) from the server to clients while nobody is holding it. Both sides: the server writes the angle, clients ease towards it.

Constructors​

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

Fields​

MemberWhat it is
static AccumulativeAverageCount prepareForWriteTimerStatic timing stats for PrepareForWrite across all pivots.
static AccumulativeAverageCount serializeTimerStatic timing stats for Serialize across all pivots.
10 private and internal fields
MemberWhat it is
private Vector3 axisLocal rotation axis (normalized) that is synced.
private float lerpSpeedFraction of the remaining angle closed each fixed update on clients.
private float maxValueHighest angle in degrees the sync range covers.
private float minValueLowest angle in degrees the sync range covers.
private float precisionAngle precision used for compression and the at-target check.
private Pickup targetPickupThe pickup whose held state decides when the angle is synced.
private float targetRotationLast angle written by the server or read by the client.
private Transform targetTransformThe transform whose local rotation is synced.
private IUnityUpdateMethod updateHandle of the registered client easing update, if running.
private static UpdateModule updateModuleFixed-update module the easing update runs in.

Properties​

3 private and internal properties
MemberWhat it is
private int Alta.Networking.INetworkSerialized.MaximumBits { get; }Bits needed for the held flag plus the angle at the set range and precision.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; }Shared timing stats for PrepareForWrite.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; }Shared timing stats for Serialize.

Methods​

MemberWhat it is
override void Initialize()Client: hooks the pickup's interaction start and scene destroy so the easing update stops.
7 private and internal methods
MemberWhat it is
private void FinishSerialization(Interactable interactable, Interactor interactor)Client: stops the easing update when someone starts interacting with the pickup.
private bool IsAtPosition(float currentRotation)True when the given angle is within precision of the target angle.
private void OnDestroy()Client: removes the easing update.
private bool Alta.Networking.INetworkSerialized.PrepareForWrite(bool isWriteFull)Asks to send only when the pickup is not held and its rigidbody is awake.
private void SceneDestroy(NetworkEntity entity, bool isUnload)Removes the easing update when the entity is destroyed by the scene.
private void Alta.Networking.INetworkSerialized.Serialize(Stream stream, bool isWriteFull)Writes whether the pickup is held and, if not, the angle on axis. Clients snap on full reads and ease otherwise.
private void UpdateRemote()Client: eases the transform towards the target angle and stops once there and the rigidbody sleeps.