Skip to main content

FaucetHandle

A class in Root.Township, the global namespace.

Twistable handle that turns around its local Z axis while a player holds its pickup, and reports a 0 to 1 value through onValueChanged. The angle is only synced to players when they join.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private AnimationCurve angleToProgressSkewCurve mapping angle over maxAngle to the value sent to onValueChanged.
private Coroutine checkingThe running RotationCheck coroutine, if any.
private float currentAngleBacking field for CurrentAngle.
private Quaternion halfRotationRotation at half of maxAngle, used as the centre for clamping.
private float maxAngleLargest angle the handle can turn to, 1 to 180 degrees.
private float maxRotationPerSecondHow fast the handle can follow the hand, in degrees per second (its tightness).
private HandleValueEvent onValueChangedEvent fired with the 0 to 1 progress whenever the angle changes.
private MethodSyncStruct<float> syncMethod sync used to send the angle.
private Pickup targetPickupThe pickup players grab to turn the handle.

Properties​

MemberWhat it is
float CurrentAngle { get; private set; }Current handle angle in degrees. Setting it fires onValueChanged with the skewed 0 to 1 progress.

Methods​

MemberWhat it is
override void Initialize()Creates the sync method sync on SyncA.
override void InitializeAsServer(SpawnData spawnData)Server: sets CurrentAngle from the handle's starting rotation.
override void OnConnected(Player player)Server: sends the current angle to the joining player.
7 private and internal methods
MemberWhat it is
private void Awake()Works out the half-way rotation and hooks the pickup's interaction start and end events.
private void OnDrawGizmosSelected()Empty.
private void OnValidate()In play mode, recomputes the half-way rotation after maxAngle changes.
private IEnumerator RotationCheck(Interactor interactor) (iterator)Coroutine that turns the handle to follow the holding hand's twist, clamped to maxAngle and limited by maxRotationPerSecond.
private void StartCheck(Interactable target, Interactor interactor)Starts RotationCheck for the hand that grabbed the pickup.
private void StopCheck(Interactable target, Interactor interactor)Stops RotationCheck when the pickup is let go.
private void Sync(IPlayer player, Stream stream, float angle)Writes the angle, and on a client applies the received angle to the rotation and CurrentAngle.