TimberBlockSpawner
A class in Root.Township, Alta.Carpentry.
The sliding block holder on a chiselling deck (deck.BlockPositioner). Players drag it by its handles between set positions, and the position sets the biggest block allowed. It can also flip the block over.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour - Nested types
ChiselingSizePoint,SizedSpawnPoints - Documented in Farming, woodcutting and carpentry
Constructors
| Member | What it is |
|---|---|
TimberBlockSpawner() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
23 private and internal fields
| Member | What it is |
|---|---|
private TimberBlockSpawner.ChiselingSizePoint[] availablePoints | The positions on the track, each with the biggest block size it allows. |
private Vector3 basePosition | Local starting position; only x changes as it slides. |
private Quaternion baserotation | Local rotation kept while dragging. |
private float blockSpawnMoveSpeed | Slide speed when moving on its own. |
private float blockUnitLength | Serialized value not read in this build. |
private float buiderBaseX | BuilderX when there is no block or no matching spawn point. |
private Coroutine checkingPosition | Private: the running CheckPosition coroutine. Non null means held. |
private int currentPoint | Private: index of the current position in availablePoints. |
private ChisellingDeck deck | The chiselling deck this holder belongs to. |
private Interactable[] handles | The grab points used to drag the holder. |
private bool isInversedUp | Private: whether the holder is flipped. |
private Rigidbody localRigidbody | Rigidbody on this object, non kinematic only while dragged. |
private float maxValue | Highest x the holder can slide to. |
private float minValue | Lowest x the holder can slide to. |
private Coroutine movingSpawnPosition | Private: the running slide coroutine. |
private DurationCurve rotationAnimation | Duration and curve of the flip. |
private Coroutine rotationCoroutine | Private: the running flip coroutine. |
private Transform rotationHandleTransform | Its rotation sets which way the flip turns. |
private Transform rotationParent | The transform turned by the flip. |
private TimberBlockSpawner.SizedSpawnPoints[] spawnPositions | Spawn point and BuilderX for each block size. |
private MethodSync syncPosition | Private: message for SyncPosition. |
private MethodSyncStruct<bool> syncRotation | Private: message for SyncRotation. |
private float target | X position the holder is at or sliding to. |
Properties
| Member | What it is |
|---|---|
float BuilderX { get; } | X position for the wedge display, from the spawn point matching the current block size, or the base value. |
bool IsHeld { get; } | True while a player is dragging the holder. |
ChiselBlockSize MaxSize { get; } | The biggest block size the current position allows. |
Methods
| Member | What it is |
|---|---|
IEnumerator EnsureSpace() (iterator) | Coroutine: if the block is too big for the current position, slides out to the first one that fits and syncs it. |
void EnsureSpaceInstant() | Jumps straight to the first position that fits the block, without animating. |
Transform GetSpawnPosition(ChiselBlockSize size) | Returns the spawn point for a block size, or null. |
override void Initialize() | Sets up the position and rotation sync messages. |
override void OnConnected(Player player) | Sends the rotation and position to a joining player. |
void Rotate() | Server: flips the block holder over and syncs it to clients. |
bool SetupStartingPosition() | Editor: stores the base position and rotation and works out the track limits. Returns whether anything changed. |
12 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Hooks each handle's grab and release. |
private IEnumerator CheckPosition() (iterator) | Private: while dragged, keeps the holder on its track and picks the nearest position. Moving to a smaller one shrinks the block. |
private void CheckRelease(PlayerController player, Vector3 oldPosition, Vector3 newPosition) | Private: forces a player's hands off the handles. Not called in this build. |
private bool IsNewPlayer(Interactor interactor) | Private: always returns true. Not called in this build. |
private IEnumerator MoveBlockSpawn() (iterator) | Private: drops all hands, slides to target and then makes the handles usable again. |
private void OnDrawGizmosSelected() | Private, editor: draws a sphere at each position. |
private IEnumerator Rotation() (iterator) | Private: animates the 180 degree flip, then tells the block it is upside down or not. |
private void SnapPoint(Interactable interactable, Interactor interactor) | Private: when the last handle is let go, stops dragging and the local player syncs where it stopped. |
private void StartCheckingPosition(Interactable interactable, Interactor interactor) | Private: on grab, stops any slide and starts CheckPosition. |
private void StartRotation() | Private: starts the flip animation if it is not already running. |
private void SyncPosition(IPlayer player, Stream stream) | Private: syncs the target position and slides there; the server relays it to other players. |
private void SyncRotation(IPlayer player, Stream stream, bool value) | Private: syncs whether the holder is flipped; clients flip to match. |
Used in
Members of other types that take, return or hold a TimberBlockSpawner: