Skip to main content

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.

Constructors​

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

Fields​

23 private and internal fields
MemberWhat it is
private TimberBlockSpawner.ChiselingSizePoint[] availablePointsThe positions on the track, each with the biggest block size it allows.
private Vector3 basePositionLocal starting position; only x changes as it slides.
private Quaternion baserotationLocal rotation kept while dragging.
private float blockSpawnMoveSpeedSlide speed when moving on its own.
private float blockUnitLengthSerialized value not read in this build.
private float buiderBaseXBuilderX when there is no block or no matching spawn point.
private Coroutine checkingPositionPrivate: the running CheckPosition coroutine. Non null means held.
private int currentPointPrivate: index of the current position in availablePoints.
private ChisellingDeck deckThe chiselling deck this holder belongs to.
private Interactable[] handlesThe grab points used to drag the holder.
private bool isInversedUpPrivate: whether the holder is flipped.
private Rigidbody localRigidbodyRigidbody on this object, non kinematic only while dragged.
private float maxValueHighest x the holder can slide to.
private float minValueLowest x the holder can slide to.
private Coroutine movingSpawnPositionPrivate: the running slide coroutine.
private DurationCurve rotationAnimationDuration and curve of the flip.
private Coroutine rotationCoroutinePrivate: the running flip coroutine.
private Transform rotationHandleTransformIts rotation sets which way the flip turns.
private Transform rotationParentThe transform turned by the flip.
private TimberBlockSpawner.SizedSpawnPoints[] spawnPositionsSpawn point and BuilderX for each block size.
private MethodSync syncPositionPrivate: message for SyncPosition.
private MethodSyncStruct<bool> syncRotationPrivate: message for SyncRotation.
private float targetX position the holder is at or sliding to.

Properties​

MemberWhat 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​

MemberWhat 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
MemberWhat 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: