Skip to main content

GenericCraftingNail

A class in Root.Township, Alta.Crafting.

One nail on a generic crafting piece that players hammer in. Hits from its impact detector go to the piece, which decides the progress and damage; the server's state is synced through the station.

Constructors​

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

Fields​

14 private and internal fields
MemberWhat it is
private float afterDoneDisableTimerSeconds after the nail is done before its collider turns off on clients. 2 by default.
private Quaternion devianceBacking field for Deviance: how bent the nail is, capped at maxDeviance degrees.
private Timeline.IEntry disableColliderTimeline entry for the pending DisableCollider call.
private float doneDistanceExtra distance the mesh sits out while not done. 0.02 by default.
private INailable hitReceiverThe INailable that set up this nail and gets its hits and completion.
private Collider impactColliderCollider that takes hammer hits. Turned off once the nail is done.
private ImpactDetector impactDetectorBacking field for ImpactDetector, whose hits drive the nail.
private float lengthHow far the mesh sticks out at 0 progress. 0.04 by default.
private float maxDevianceMost the nail can bend, in degrees. Set by Setup.
private Transform meshTransformThe nail mesh, moved in as progress rises.
private Transform pivotTransformPivot rotated by the deviance.
private Vector3 positionPosition passed to Setup. Not read in this class.
private float progressBacking field for Progress, from 0 to 1. The nail is done at 0.99 or more.
private Renderer shellRenderer hidden once the nail is done.

Properties​

MemberWhat it is
Quaternion Deviance { get; }How far the nail is tilted from straight.
float DevianceAngles { get; }Tilt in degrees.
Vector3 DeviantDirection { get; }Nail direction with the tilt applied.
Vector3 Direction { get; }Straight direction of the nail.
ImpactDetector ImpactDetector { get; }The impact detector that receives hammer hits.
int Index { get; private set; }Position of the nail in its piece.
bool IsDone { get; private set; }True once fully hammered in.
IPlayer LastHittingPlayer { get; set; }Server: the player whose tool last hit the nail. Credited when the piece completes.
float Progress { get; private set; }How far in the nail is, 0 to 1. Setting it moves the mesh.

Methods​

MemberWhat it is
void ApplyDamage(float progressDamage)Drives the nail in by some progress and adds tilt (capped). At full progress it marks itself done and tells the piece.
void ApplyDamage(float progressDamage, Quaternion deviance)Drives the nail in by some progress and adds tilt (capped). At full progress it marks itself done and tells the piece.
static void EmptySerialize(Stream stream)Writes or skips the data of an empty nail, keeping the stream in step.
void ForceComplete()Marks the nail fully in, with no effects.
void ResetProgress()Pulls the nail back out, straight, and hides it.
void Serialize(Stream stream)Writes or reads done, progress and tilt.
void SetActive(bool isActive)Shows or hides the nail.
void Setup(INailable hitReceiver, int index, Vector3 position, float maxDeviance)Links the nail to its piece with an index, position and maximum tilt, and resets it.
protected override void OnDestroy()Cancels the collider-off timer.
7 private and internal methods
MemberWhat it is
private void Awake()Hooks DisableTimer to the nail being released back to its pool.
private void DisableCollider()Turns off the impact collider. Runs afterDoneDisableTimer seconds after the nail is done.
private void DisableTimer(PooledObject pooledObject)Cancels the pending collider disable when the nail is released to the pool.
private bool IcClientSideImpact(ImpactHit impact, out ImpactHitWithTool resultHit)True when the hit is from a tool held by a real player, so the player's client resolves it.
private void OnDrawGizmosSelected()Editor: draws a line along the nail's direction.
private void ReceiveHit(ImpactHit impact)Hit handler hooked by Setup (never unhooked). Server applies non-client hits; the local wielder's client syncs its hit and plays the effect.
private void UpdatePosition()Moves the nail mesh in by progress and tilts the pivot by the deviance.

Used in​

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