Skip to main content

BasicDecay

A class in Root.Township, the global namespace.

Server component that destroys its entity after a decay time, using a saved timeline entry so the timer carries over saves. Subclasses add conditions.

Constructors​

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

Fields​

MemberWhat it is
protected bool isDisabledSaved flag that stops decay while true.
protected static Logger loggerShared logger.
3 private and internal fields
MemberWhat it is
private Timeline.IEntry decayTimerThe timeline entry that triggers the decay check. Saved and loaded so decay carries across restarts.
private DecaySettings settingsBacking field for Settings.
private bool willDestroySet on load when the saved timer is already in the past, so the entity decays straight away.

Properties​

MemberWhat it is
DecaySettings Settings { get; set; }Decay settings: whether it's enabled and the base decay time.
protected virtual float TimerMultiplier { get; }Subclass: scales the decay time. 1 by default.

Methods​

MemberWhat it is
override void InitializeAsServer(SpawnData data)Server: starts or continues the timer, or destroys straight away if the saved timer already ran out.
protected void CancelTimer()Cancels the running timer.
protected virtual void DecayFailed()Subclass: called when the timer ran out but decay wasn't valid.
protected float EvaluateDecayTime()Seconds until decay: settings time times the multiplier, divided by the server's decay multiplier.
protected virtual void FinishInitialize()Starts the timer. Subclasses can delay this.
protected virtual bool IsDecayValid(bool isStarting)Whether the entity may decay now. True if enabled and not disabled.
protected void ResetTimer()Cancels and starts a fresh timer.
protected void StartOrContinueTimer()Starts the timer if none is running and decay is valid.
protected void StartOrShortenTimer()Restarts the timer if the time left is longer than a fresh decay time.
4 private and internal methods
MemberWhat it is
private void CheckDecay()Runs when the timer fires (or on load): if decay is still valid, destroys the entity next frame, otherwise calls DecayFailed.
private bool CheckDecay(bool isOnLoad)Runs when the timer fires (or on load): if decay is still valid, destroys the entity next frame, otherwise calls DecayFailed.
private void OnDestroy()Cancels the decay timer.
private void ICleanOnSerialize.OnSerialize()Cancels the timer when the entity is serialized away (ICleanOnSerialize).