Skip to main content

GenericCraftingPiece

A class in Root.Township, Alta.Crafting.

One ghost piece of a generic crafting station's project. Placing the right item fills it with that item's material; hammering its nails completes it before a timer pops it back out. A pooled object on both sides; the station syncs it.

Constructors​

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

Fields​

16 private and internal fields
MemberWhat it is
private static readonly int _ProgressShader property ID for the cracks progress.
private Vector3 centerPositionLocal centre of the piece mesh, behind CenterPosition.
private MeshRenderer cracksMeshRendererRenderer for the cracks overlay shown as failure health drops.
private GenericCraftingPieceDefinition definitionThe recipe's definition for this piece: mesh, nails, failure health, level and source item.
private float failureHealthHealth left before bad nail hits break the piece and fail the project. Saved.
private bool hasCracksWhether the cracks overlay should show.
private MeshRenderer mainMeshRendererRenderer for the piece. Shows ghost, highlight or the placed material.
private MeshCollider meshColliderCollider for the piece, on only while it's filled.
private MeshFilter[] meshFiltersMesh filters given the definition's mesh.
private Timeline.IEntry playTimeEndingSoundTimeline entry for PlayTimeEndingSound.
private Interactable popInteractableInteractable players grab to pull a filled piece back out.
private Timeline.IEntry popoutEntryServer: timeline entry for Popout, started when the piece is filled.
private MaterialPropertyBlock progressPropertyMaterial property block that sets the cracks progress.
private IProject projectThe project this piece belongs to.
private int rangeLevelDistance LOD level from UpdateDistance: 0 is near.
private Transform targetTransformTransform placed at the definition's position, rotation and scale.

Properties​

MemberWhat it is
Bounds Bounds { get; }World bounds of the piece's mesh.
Vector3 CenterPosition { get; }World centre of the piece's mesh.
int Hash { get; }Identifier of this piece in the recipe.
bool IsComplete { get; private set; }True once all its nails are done.
bool IsEnabled { get; private set; }True when the piece can be filled (its level is open).
bool IsFilled { get; private set; }True when an item has been placed in it.
int Level { get; }The build level this piece belongs to.
PhysicalMaterial Material { get; private set; }Physical material of the item placed in it, or null.
GenericCraftingNail[] Nails { get; private set; }The piece's nails.
int ResultHash { get; }Result hash from the piece definition.
Quaternion Rotation { get; private set; }World rotation of the piece.

Methods​

MemberWhat it is
bool AcceptsComponent(GenericCraftingComponent component)True if the piece is enabled, empty and the component is the right source item.
void ApplySaveData(PieceSaveData saveData, Chunk chunk)Server: restores the piece from a save. An unfinished filled piece comes back as a loose item instead.
bool CanRemove()True if filled, and either unfinished or at a level the project allows removing.
void CheckFailPop()May pop a completed piece out at random, more likely the more it was damaged.
void Clear()Empties the piece, releases its nails and returns it to the pool.
void Empty()Removes the material, resetting the piece's progress.
void ForceComplete()Completes every nail and the piece, without effects.
PieceSaveData GetSaveData()Returns the piece's hash, completion, damage and material for saving.
void OnComplete(GenericCraftingNail nail, bool hasEffects)Called when a nail finishes; completes the piece if all nails are done and tells the project.
void PlayDestroyEffect()Plays the effect for a piece breaking from bad hits.
void ReceiveChiselHit(float damage)Server: pops the piece out if a chisel hit is strong enough and it can be removed.
void SetAnimate(bool isAnimating)Highlights an empty enabled piece, or turns the highlight off.
void SetEnabled(bool isEnabled)Opens or closes the piece. Closing a filled piece drops its item back out.
void SetMaterial(PhysicalMaterial material)Fills the piece with a material, or empties it with null. On the server, filling starts the timer that pops it if nails aren't done.
void Setup(IProject project, GenericCraftingPieceDefinition definition)Sets the piece up from its definition for a project: transform, meshes, nails.
NetworkEntity SpawnRefuse()Spawns the placed item back out as a loose item with its material.
void SyncFailure(Stream stream)Writes or reads how damaged the piece is, which drives the crack visuals.
void SyncFull(Stream stream)Writes or reads the piece state and every nail.
void SyncGrab(Stream stream)Client to server: a player grabbed the filled piece, so the server pops it into their hand.
void SyncState(Stream stream, bool hasEffects)Writes or reads enabled, complete and filled state and the material.
void UpdateDistance(int rangeLevel)Shows or hides the meshes for a distance level.
17 private and internal methods
MemberWhat it is
private void Awake()Creates the shader property block on clients and hooks the pop interactable's filter and grab events.
private bool CheckIsComplete()True when every nail on the piece is done.
private void FilterPop(Interactor interactor, Interactable interactable, ref bool result)Only lets a player pull the piece out when it's filled, no nail is done, its level can be removed and the project isn't complete.
private void GetCompleteEffect()Client: plays the piece-completed particle effect and event.
private void Grab(Interactable interactable, Interactor interactor)Server pops the piece into the grabbing hand as a loose item; a client asks the server to do that.
private bool Alta.Crafting.INailable.HasOverflow(GenericCraftingNail nail, ImpactHit impact)Explicit INailable method: whether a hit on a nail would push it past full progress.
private void LoadCompletePiece(PhysicalMaterial material)Server: restores a saved complete piece with its material and every nail finished.
private void OnDrawGizmosSelected()Editor gizmo at the piece's centre.
private void PlayTimeEndingSound()Plays the warning sound shortly before the nailing time runs out.
private NetworkEntity Pop()Spawns the piece's material back as a loose item, empties the piece and re-checks the project level.
private void Popout()Called when the nailing time runs out: if the piece isn't complete, it pops out as a loose item.
private void Alta.Crafting.INailable.ReceiveHit(GenericCraftingNail nail, Vector3 impactDirection, float impactDamage)Explicit INailable method: applies a hammer hit to a nail, damaging the piece's failure health and failing the project if it runs out.
private void ResetValues()Clears completion, restores failure health, resets every nail and turns off the pop interactable.
private NetworkEntity SpawnChunkedRefuseWithMaterial(PhysicalMaterial material, Chunk chunk)Spawns the piece's source item in the given chunk at the piece, set up as refuse with that material.
private void SpawnRefuseForInteractor(Interactor interactor)Pops the piece and puts the loose item straight into the interactor's hand.
private void Alta.Crafting.INailable.SyncHit(GenericCraftingNail nail, ImpactHitWithTool hitWithTool)Explicit INailable method: forwards a client's nail hit to the station to send to the server.
private void UpdateCracks(float cracksProgress)Client: shows the cracks overlay at the given progress, only at the nearest LOD.

Used in​

Members of other types that take, return or hold a GenericCraftingPiece: