GrowerComponent
A class in Root.Township, the global namespace.
Server: grows something through the stages of a GrowthDefinition (sapling to tree, for example), spawning each stage's prefab as a child and moving on after each stage's duration. Saved, and catches up on load.
- Listed in Global namespace: E to H
- Inherits or implements
NetworkEntityBehaviour,IGrowthStage,ISavable<GrowthSaveData>,ISavableSave<GrowthSaveData>,ISavableSaveBase - Derived types
GrowthSaveData - Documented in Farming, woodcutting and carpentry
Constructors
| Member | What it is |
|---|---|
GrowerComponent() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
8 private and internal fields
| Member | What it is |
|---|---|
private bool autoStart | If true, growing starts one frame after the server spawns the grower. |
private static Collider[] colliders | Shared overlap buffer for the radius check. |
private GrowthDefinition growthDefinition | The stages to grow through. Saved, so a loaded grower keeps its definition. |
private static HashSet<Rigidbody> handledRigidbodies | Shared set so each rigidbody is checked once per radius check. |
private static RaycastHit[] hits | Shared raycast buffer for the raycast check. |
private static Logger logger | NLog logger for this class. |
private Timeline.IEntry nextStageTimer | Timeline entry for the next stage or retry. |
private TimeSpan startedTime | Timeline time growth started. Used on load to work out which stage it should be in now. |
Properties
| Member | What it is |
|---|---|
GrowthStage CurrentStage { get; } | The current stage's settings. |
NetworkEntity CurrentStageEntity { get; private set; } | The spawned object for the current stage, or null. |
int CurrentStageIndex { get; private set; } | Index of the current stage. |
bool IsRunning { get; private set; } | True once growth has started. |
bool IsSetup { get; } | True when the grower has a growth definition. |
int SpawnedPrefabStageIndex { get; private set; } | Stage whose prefab is spawned now, or -1. Can lag behind for stages that reuse the previous prefab. |
Methods
| Member | What it is |
|---|---|
override void InitializeAsServer(SpawnData spawnData) | Starts growing on the next frame if auto start is on. |
void StartGrowing() | Starts at stage 0. Each stage checks survival chance, spacing and a raycast, retrying or dying if they fail. |
void StopGrowth(bool isKeepingChild) | Destroys the grower. Pass true to keep the grown object, which is then moved out to the chunk or the parent. |
16 private and internal methods
| Member | What it is |
|---|---|
private bool CheckRadius(GrowthStage currentStage) | Fails if another growing thing whose current stage uses a radius sits within the smaller of the two separation radii. |
private bool CheckRaycast(GrowthStage currentStage) | If the stage uses a raycast check, fails when the ray hits anything other than the current stage's own rigidbody. |
private void DestroyCurrentStage() | Destroys the spawned stage object and clears the spawned stage index. |
private void DestroySelf() | Cancels the stage timer, destroys the current stage object and the grower entity. |
private void GoToStage(int stageIndex, TimeSpan timeLeft = null) | Runs the checks for a stage and handles the result. Logs errors instead of throwing. |
private void HandleChecksResult(int stageIndex, GrowthStage currentStage, bool checksResult, TimeSpan timeLeft = null) | On pass, spawns the stage and schedules the next one (or ends growth keeping the result). On fail, retries later or destroys everything. |
private void HandleChildDestroyed(NetworkEntity entity, bool isUnload) | Stops growth (destroying the grower) when the stage object is destroyed, but not when it's only unloaded. |
private void HandleLoadedCurrentStageEntity(NetworkPrefab prefab, NetworkEntity parent, int childIndex) | Load callback that sets the saved stage object as the current one. |
private void HandlePrefabKinematic(GrowthStage currentStage, NetworkEntity spawned) | Forces the spawned stage's rigidbody kinematic or not, if the stage asks for it. Warns if there's no rigidbody. |
private void LoadStage(int currentStageIndex, TimeSpan timeLeft) | After load, catches up through stages skipped while unloaded, running each check, then goes to the target stage. |
private void OnDestroy() | Cancels the pending stage timer. |
private bool PerformStageChecks(int stageIndex) | Rolls the previous stage's survival rate, then runs the radius and raycast checks. |
private void SetCurrentStageEntity(NetworkEntity entity) | Sets the current stage object and moves the destroyed and parent-changed hooks to it. |
private NetworkEntity SpawnPrefab(GrowthStage currentStage, int stageIndex) | Spawns the stage's prefab (or a preset tree) as a saved child, or keeps the previous prefab if the stage reuses it. |
private void StageEntityUnchilded(NetworkEntity topic, NetworkEntity oldParent, NetworkEntity newParent) | If the stage object is moved off the grower (for example picked up), lets it go and destroys the grower next frame. |
private void UnchildSpawned() | At the end of growth, detaches the final object so it stays in the world on its own (or under the grower's chunking parent). |
Used in
Members of other types that take, return or hold a GrowerComponent: