GrowthItem
A class in Root.Township, the global namespace.
One growing plant inside a GrowerGroup: steps through a GrowthDefinition's stages on timeline timers, spawning each stage's prefab as a child. Server side.
- Listed in Global namespace: E to H
Constructors
| Member | What it is |
|---|---|
GrowthItem() | Creates a GrowthItem with default values. |
Fields
| Member | What it is |
|---|---|
int currentStage | Index of the stage reached. |
GrowthDefinition definition | The GrowthDefinition with the stages to grow through. |
NetworkEntity entity | The spawned entity for the current stage, or null. |
bool hasStarted | True once StartGrowing has run. |
Timeline.IEntry nextStageTimer | Timeline entry for the next stage or retry. Cancelled when growth stops. |
IGrowthManager parent | The IGrowthManager (group) that owns this item. |
Vector3 position | Local position in the parent group. |
Quaternion rotation | Local rotation in the parent group. |
int spawnedStageIndex | Index of the stage whose prefab is spawned, or -1. |
TimeSpan startedTime | Timeline time when growth started. |
4 private and internal fields
Properties
| Member | What it is |
|---|---|
Vector3 WorldPosition { get; } | The item's local position turned into world space through the parent group. |
Events
| Member | What it is |
|---|---|
event Action<GrowthItem> Destroyed | Raised when growth stops without keeping the plant, such as a failed check or the stage entity being destroyed. |
event Action<GrowthItem, NetworkEntity> EntityAdded | Raised when a stage entity is attached to this item. |
event Action<GrowthItem, NetworkEntity> EntityRemoved | Raised when the stage entity is detached or destroyed. |
event Action<GrowthItem> Removed | Raised the frame after the stage entity is taken out of the group (picked). |
Methods
| Member | What it is |
|---|---|
void GoToStage(int stageIndex, TimeSpan timeLeft = null) | Runs the checks for a stage, then spawns it and schedules the next, retries, or stops growth. |
void LoadEntity(NetworkEntity entity) | Attaches an already spawned stage entity, used when loading a save. |
void LoadStage(int newIndex, TimeSpan timeLeft) | Restores a saved stage, running checks for the skipped stages and resuming with the saved time left. |
void OnDestroy() | Cancels the next stage timer. |
void StartGrowing() | Starts at stage 0 if not already started and the parent is not being destroyed. |
void StopGrowth(bool isKeepingChild) | Cancels the timer. Keeping the child unparents the last stage if the group destroys itself at the end; otherwise the stage is destroyed. |
12 private and internal methods
| Member | What it is |
|---|---|
private bool CheckRadius(GrowthStage currentStage) | Stage check: fails if another growing entity's current stage (with a separation radius) is closer than the smaller of the two radii. |
private bool CheckRaycast(GrowthStage currentStage) | Stage check: casts along the stage's ray direction from the growth point and fails if it hits anything but the current entity. |
private void DestroyCurrentStage() | Destroys the entity spawned for the current stage and stops tracking it. |
private void HandleChecksResult(int stageIndex, GrowthStage currentStage, bool checksResult, TimeSpan timeLeft = null) | After the stage checks: on success spawns the stage and schedules the next one; on failure retries later or stops and destroys the item. |
private void HandleChildDestroyed(NetworkEntity entity, bool isUnload) | Stops growth and destroys the item when the stage entity is destroyed, but not when it is only unloaded. |
private void HandlePrefabKinematic(GrowthStage currentStage, NetworkEntity spawned) | Forces the spawned stage's rigidbody kinematic or non-kinematic when the stage's ForceKinematic asks for it. |
private bool PerformStageChecks(int stageIndex) | Runs a stage's checks: the previous stage's survival roll, then the radius and raycast checks. |
private void Picked() | Raises Removed. Called a frame after the stage entity is moved off the growth parent, for example when picked up. |
private void SetCurrentStageEntity(NetworkEntity newEntity) | Swaps the tracked stage entity, moving the destroy and parent-changed listeners and raising EntityRemoved and EntityAdded. |
private NetworkEntity SpawnPrefab(GrowthStage currentStage, int stageIndex) | Spawns the stage's prefab (or a runtime tree for a PresetTree) under the parent, or keeps the previous stage's entity when the stage reuses it. |
private void StageEntityUnchilded(NetworkEntity topic, NetworkEntity oldParent, NetworkEntity newParent) | When the stage entity gets a new parent, stops tracking it, fixes its transform parent if needed and calls Picked next frame. |
private void UnchildSpawned() | At the end of growth, frees the final entity: moves it to the parent's chunking parent, or makes it a standalone saved entity in the chunk. |
Used in
Members of other types that take, return or hold a GrowthItem: