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.
- Listed in Crafting and making
- Inherits or implements
PooledObject - Attributes
SelectionBase - Documented in Crafting
Constructors
| Member | What it is |
|---|---|
GenericCraftingNail() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private float afterDoneDisableTimer | Seconds after the nail is done before its collider turns off on clients. 2 by default. |
private Quaternion deviance | Backing field for Deviance: how bent the nail is, capped at maxDeviance degrees. |
private Timeline.IEntry disableCollider | Timeline entry for the pending DisableCollider call. |
private float doneDistance | Extra distance the mesh sits out while not done. 0.02 by default. |
private INailable hitReceiver | The INailable that set up this nail and gets its hits and completion. |
private Collider impactCollider | Collider that takes hammer hits. Turned off once the nail is done. |
private ImpactDetector impactDetector | Backing field for ImpactDetector, whose hits drive the nail. |
private float length | How far the mesh sticks out at 0 progress. 0.04 by default. |
private float maxDeviance | Most the nail can bend, in degrees. Set by Setup. |
private Transform meshTransform | The nail mesh, moved in as progress rises. |
private Transform pivotTransform | Pivot rotated by the deviance. |
private Vector3 position | Position passed to Setup. Not read in this class. |
private float progress | Backing field for Progress, from 0 to 1. The nail is done at 0.99 or more. |
private Renderer shell | Renderer hidden once the nail is done. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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:
ConfirmationCraftingPart.HasOverflow, ConfirmationCraftingPart.nails, ConfirmationCraftingPart.OnComplete, ConfirmationCraftingPart.ReceiveHit, ConfirmationCraftingPart.SyncHit, GenericCraftingPiece.HasOverflow, GenericCraftingPiece.Nails, GenericCraftingPiece.OnComplete, GenericCraftingPiece.ReceiveHit, GenericCraftingPiece.SyncHit, INailable.HasOverflow, INailable.OnComplete, INailable.ReceiveHit, INailable.SyncHit, NailIdentifier.Setup, NailSettings.CalculateNailDamage, NailSettings.SetupNails.