Skip to main content

Fuse

A class in Root.Township, the global namespace.

A burning fuse, as on dynamite. Once lit (a hit lights it) it burns down over FuseTime and the server raises Finished, probably what sets off the explosion.

Constructors​

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

Fields​

19 private and internal fields
MemberWhat it is
private float currentFuseAmountFuse left, from 1 (full) to 0 (exploded). Backing field for CurrentFuseAmount.
private float damageThresholdDamage that should set it off, per the tooltip. Not used in this file.
private Fuse.DockSettings dockSettingsHow a lit fuse limits docking: Default, Single (only into an empty dock, then blocks it) or Blocked.
private AltaEvent finishedOnServerEvent raised on the server when the fuse burns out. Exposed as Finished.
private MethodSync finishSyncMethod sync for the DynamiteExplosion message.
private Transform fuseTransform scaled along Y to show how much fuse is left.
private AltaCoroutine fuseCoroutineThe running FuseTimer coroutine.
private float fuseLengthFull length of the fuse visual. Backing field for FuseLength.
private float fuseTimeSeconds from lighting to finishing. Backing field for FuseTime.
private ImpactDetector impactDetectorOptional impact detector. Any hit lights the fuse.
private bool isFinishedTrue once the fuse has burnt out. Backing field for IsFinished.
private bool isLitTrue while burning. Backing field for IsLit.
private bool isPreventingDockingWhenLitIf set, a lit fuse can only dock into docks with one of whenLitAcceptOnlyTags.
private GameObject litEffectObject shown while lit, hidden when docked small.
private Pickup pickupThe pickup holding the fuse. Made transient while lit.
private AltaEvent startedEvent raised when the fuse is lit.
private AltaEvent stoppedEvent raised when the fuse is put out.
private MethodSync syncMethod sync for the DynamiteFuseProgress message. Sent to players as they connect.
private PickupTag[] whenLitAcceptOnlyTagsDock tags a lit fuse may still dock into when isPreventingDockingWhenLit is set.

Properties​

MemberWhat it is
float CurrentFuseAmount { get; set; }How much fuse is left, from 1 (full) to 0. Setting it updates the fuse visual.
float FuseLength { get; set; }Full length of the fuse visual. Setting it updates the visual.
float FuseTime { get; set; }Seconds from lighting to burning out.
bool IsFinished { get; }True once the fuse has burned out. A finished fuse cannot be lit again.
bool IsLit { get; }True while the fuse is burning.
1 private and internal property
MemberWhat it is
private bool Alta.Heat.IFlammable.IsIgnoringSparks { get; }Always false, so sparks can light the fuse.

Events​

MemberWhat it is
event Action FinishedServer: raised when the fuse burns out. Adds to the finishedOnServer event set in the prefab.

Methods​

MemberWhat it is
override void Initialize()Sets up the fuse syncs and the dock rules (default, single, or blocked while lit).
override void InitializeAsServer(SpawnData spawnData)Server: restarts the burn timer if the fuse was saved while lit.
override void OnConnected(Player player)Server: sends the fuse state to the joining player.
void ToggleLight(bool isLit)Calls TryLight or Unlight.
void TryLight()Server: lights the fuse, makes the pickup transient, syncs and starts the burn timer. Ignored if already lit or finished.
void Unlight()Server: puts the fuse out and resets it to full length.
void UpdateFuse()Client: scales the fuse visual to the remaining amount and shows the lit effect while burning.
15 private and internal methods
MemberWhat it is
private void Block(Interactor interactor, Pickup pickup, ref bool isBlocked)Dock filter that blocks everything. Added to the dock a lit fuse sits in when dockSettings is Single.
private void CancelFuse(NetworkEntity entity, bool isUnload)Stops the fuse coroutine when the scene destroys the entity.
private void CheckBlock(Interactor interactor, Pickup pickup, PickupDock dock)On docking while lit, blocks that dock from taking anything else.
private void DockFilter(Interactor interactor, PickupDock dock, ref bool result)While lit, stops the pickup docking at all (Blocked) or into a dock that already holds something (Single).
private void FilterAllDocking(Interactor interactor, PickupDock dock, ref bool result)While lit with isPreventingDockingWhenLit, only allows docks whose tags include one of whenLitAcceptOnlyTags.
private void FinishSync(IPlayer player, Stream stream)Client: marks the fuse finished and undocks the pickup when the server says it exploded.
private IEnumerator FuseTimer() (iterator)Coroutine that burns the fuse down over fuseTime seconds. Server: at zero, syncs, undocks and drops the pickup, and raises Finished.
private void OnDisable()Unhooks the impact detector.
private void OnEnable()Hooks the impact detector so a hit lights the fuse.
private void OnHit(ImpactHit impact)Clears the impact detector's settings and tries to light the fuse.
private void ICleanOnSerialize.OnSerialize()Puts the fuse out before the entity is serialized, so copies aren't saved lit.
private void Serialize(Stream stream)Writes or reads the finished flag, and if not finished, the lit flag and fuse amount. Updates the visual on read.
private void StartTimer()Restarts the fuse coroutine and hooks cancelling it if the entity is destroyed.
private void SyncFuse(IPlayer player, Stream stream)Server to client sync of the fuse state. Client: starts or stops the burn, effects and dock rules to match.
private void Unblock(Interactor interactor, Pickup pickup, PickupDock dock)Removes the Block filter from the dock the pickup left.