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.
- Listed in Global namespace: E to H
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
FaucetHandle() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
9 private and internal fields
| Member | What it is |
|---|---|
private AnimationCurve angleToProgressSkew | Curve mapping angle over maxAngle to the value sent to onValueChanged. |
private Coroutine checking | The running RotationCheck coroutine, if any. |
private float currentAngle | Backing field for CurrentAngle. |
private Quaternion halfRotation | Rotation at half of maxAngle, used as the centre for clamping. |
private float maxAngle | Largest angle the handle can turn to, 1 to 180 degrees. |
private float maxRotationPerSecond | How fast the handle can follow the hand, in degrees per second (its tightness). |
private HandleValueEvent onValueChanged | Event fired with the 0 to 1 progress whenever the angle changes. |
private MethodSyncStruct<float> sync | Method sync used to send the angle. |
private Pickup targetPickup | The pickup players grab to turn the handle. |
Properties
| Member | What it is |
|---|---|
float CurrentAngle { get; private set; } | Current handle angle in degrees. Setting it fires onValueChanged with the skewed 0 to 1 progress. |
Methods
| Member | What 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
| Member | What 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. |