Crank
A class in Root.Township, the global namespace.
A handle you grab and turn, giving a value from 0 to 1 that changes with each turn. Server side by default; set isRunningOnClients to work it out on each client instead.
- Listed in Global namespace: C to D
- Inherits or implements
NetworkEntityBehaviour,ISavable<CrankSaveData>,ISavableSave<CrankSaveData>,ISavableSaveBase,IDeltaControl - Derived types
CrankSaveData
Constructors
| Member | What it is |
|---|---|
Crank() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
24 private and internal fields
| Member | What it is |
|---|---|
private Vector3 clampedOffset | Private: not used in this build. |
private float currentAngle | Private: the hand's angle around the axis at the last update. |
private Interactor currentInteractor | Private: the hand being tracked. |
private float difference | Private: angle change since the last update, in degrees. |
private float direction | Private: 1 for clockwise, -1 otherwise. |
private Vector3 handOrientationAxis | Axis the handle twists around to match the hand. Zero means use orientationAxis. |
private bool isActive | Private: not used in this build. |
private bool isClockwise | Whether turning clockwise raises the value. |
private bool isRunningOnClients | If set, each client works out the value itself and the server does not sync it. |
private Vector3 lastPosition | Private: the hand's last position relative to rotationCenter. |
private float lengthPerRevolution | How much the value changes for one full turn. Defaults to 1. |
private FloatEvent onRotated | Event raised each update with the angle turned, in degrees. |
private FloatEvent onValueChanged | Event raised with the new value. |
private bool orientatesToHand | Whether the handle twists to match the hand when held by one hand. |
private Vector3 orientationAxis | Local axis the target turns around. |
private Pickup pickup | The pickup players grab to turn the crank. |
private bool rotatesAroundAxis | Whether the target turns with the hand at all. |
private Transform rotationCenter | Transform the hand position is measured from. |
private float rotationOffset | Serialized value not read in this build. |
private MethodSync syncReleasePosition | Private: message for SyncReleasePosition. |
private MethodSync syncValue | Private: message for SerializeValue. |
private Transform target | The transform that turns. |
private IUnityUpdateMethod updateMethod | Private: the registered fixed update while held. |
private float value | Backing field for Value. |
Properties
| Member | What it is |
|---|---|
float Value { get; protected set; } | The crank's value, from 0 to 1. Changing it raises ValueChanged. It is saved. |
Events
| Member | What it is |
|---|---|
event Action<float> DeltaProvided | Raised each update while turned, with the value change before clamping. |
event Action<Crank, float> ValueChanged | Raised with the crank and its new value whenever the value changes. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the value and release rotation sync messages. |
override void OnConnected(Player player) | Sends the current value to a joining player. |
12 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Sets the turn direction, defaults the hand axis to the turn axis and hooks the pickup's grab and release. |
private void OnValidate() | Private, editor: updates the direction from isClockwise. |
private void OnValueChanged() | Private: raises ValueChanged and onValueChanged; the server also syncs the value unless clients run it. |
private void SerializeValue(IPlayer player, Stream stream) | Private: syncs the value. The server ignores values sent by clients. |
private void SetDirection() | Private: sets direction to 1 or -1 from isClockwise. |
private void Start() | Private: raises the value changed events once with the starting value. |
private void StartTrack(Interactable interactable, Interactor interactor) | Private: starts following the grabbing hand every fixed update. |
private void StopTrack(Interactable interactable, Interactor interactor) | Private: when the last hand lets go, stops tracking, makes the pickup kinematic and the local player syncs where it was left. |
private void SyncReleasePosition(IPlayer player, Stream stream) | Private: syncs the handle's rotation after release; the server relays it to other players. |
private void TrackHands() | Private: turns the target to follow the hand around the axis, and twists the handle to match the hand if orientatesToHand is set. |
private void UpdateCrank() | Private: fixed update while held. Tracks the hand, and updates the value on the server or when clients run it. |
private void UpdateValues() | Private: turns the angle change since the last update into a value change, raises the rotation events and clamps the value. |
Used in
Members of other types that take, return or hold a Crank: