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.
- Listed in Global namespace: A to B
- Inherits or implements
NetworkEntityBehaviour,ISavable<BasicDecayData>,ISavableSave<BasicDecayData>,ISavableSaveBase,ICleanOnSerialize - Derived types
TreeDecay,BasicDecayData,PickupDecay
Constructors
| Member | What it is |
|---|---|
BasicDecay() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected bool isDisabled | Saved flag that stops decay while true. |
protected static Logger logger | Shared logger. |
3 private and internal fields
| Member | What it is |
|---|---|
private Timeline.IEntry decayTimer | The timeline entry that triggers the decay check. Saved and loaded so decay carries across restarts. |
private DecaySettings settings | Backing field for Settings. |
private bool willDestroy | Set on load when the saved timer is already in the past, so the entity decays straight away. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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). |