Skip to main content

GachaHandle

A class in Root.Township, the global namespace.

A crank or lever handle turned by grabbing it. Turning past a threshold fires onActivated; let go and it springs back. Rotation runs locally for the holder.

Constructors​

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

Fields​

21 private and internal fields
MemberWhat it is
private AnimationCurve activationCurveMaps the raw hand angle to the handle angle.
private bool alignsPickupWithHandPosition-based option shown in the inspector. Not read in this code.
private float angleActivationThresholdAngle (after the curve) that activates the handle.
private float currentAngleCurrent handle angle in degrees.
private Interactor currentInteractorHand holding the handle, or null.
private Quaternion inputRotationAccumulated hand rotation since the grab.
private bool isActivatedTrue after the threshold was passed, until reset.
private bool isInvertedTurns the handle the other way around Z.
private bool isPositionBasedFollows the hand's position around positionCenter instead of the hand's facing.
private bool isResettingAutomaticClears activation when the handle returns to rest. Otherwise call ResetActivation.
private Vector3 latestHandForwardHand direction or position from the last frame, in the parent's space.
private float maxAngleLargest angle the handle can turn (1 to 180).
private AltaEvent onActivatedEvent fired when the handle passes the threshold.
private AltaEvent onResetEvent fired by ResetActivation.
private Transform positionCenterPivot rotated in position-based mode.
private float revertSpeedDegrees per second the handle springs back.
private MethodSyncStruct<float> syncMethod sync for the angle.
private Transform targetTransform of the handle pickup, rotated in facing mode.
private Pickup targetPickupThe pickup players grab.
private IUnityUpdateMethod updateRotationRegistered update method (turning or reverting).
private Matrix4x4 worldToLocalParent's world to local matrix captured on grab.

Methods​

MemberWhat it is
override void Initialize()Sets up the angle sync message.
override void InitializeAsServer(SpawnData spawnData)Server: starts at angle 0.
override void OnConnected(Player player)Sends the current angle to a joining player. This is the only place the angle is sent.
void ResetActivation()If activated, clears it, snaps the handle back and fires onReset.
9 private and internal methods
MemberWhat it is
private void Awake()Hooks the handle pickup's filter, grab and release events.
private void FilterInteraction(Interactor interactor, Interactable interactable, ref bool result)Blocks grabbing while activated.
private void OnDestroy()Stops the update method.
private void OnDrawGizmosSelected()Empty.
private void RevertRotation()Each frame after release, turns the handle back to rest; at rest clears activation if isResettingAutomatic.
private void StartCheck(Interactable pickup, Interactor interactor)On grab, records the hand's start direction and starts UpdateRotation.
private void StopCheck(Interactable pickup, Interactor interactor)On release, switches to RevertRotation.
private void Sync(IPlayer player, Stream stream, float angle)Sync handler: clients apply the received angle to the handle.
private void UpdateRotation()Each frame while held, turns the handle with the hand around Z; past the threshold, activates and locks at maxAngle.