Skip to main content

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.

Constructors​

MemberWhat it is
GrowthItem()Creates a GrowthItem with default values.

Fields​

MemberWhat it is
int currentStageIndex of the stage reached.
GrowthDefinition definitionThe GrowthDefinition with the stages to grow through.
NetworkEntity entityThe spawned entity for the current stage, or null.
bool hasStartedTrue once StartGrowing has run.
Timeline.IEntry nextStageTimerTimeline entry for the next stage or retry. Cancelled when growth stops.
IGrowthManager parentThe IGrowthManager (group) that owns this item.
Vector3 positionLocal position in the parent group.
Quaternion rotationLocal rotation in the parent group.
int spawnedStageIndexIndex of the stage whose prefab is spawned, or -1.
TimeSpan startedTimeTimeline time when growth started.
4 private and internal fields
MemberWhat it is
private static Collider[] collidersShared buffer for the radius check overlap.
private static HashSet<Rigidbody> handledRigidbodiesShared set so the radius check looks at each rigidbody once.
private static RaycastHit[] hitsShared buffer for the raycast check.
private static Logger loggerLogger for this class.

Properties​

MemberWhat it is
Vector3 WorldPosition { get; }The item's local position turned into world space through the parent group.

Events​

MemberWhat it is
event Action<GrowthItem> DestroyedRaised when growth stops without keeping the plant, such as a failed check or the stage entity being destroyed.
event Action<GrowthItem, NetworkEntity> EntityAddedRaised when a stage entity is attached to this item.
event Action<GrowthItem, NetworkEntity> EntityRemovedRaised when the stage entity is detached or destroyed.
event Action<GrowthItem> RemovedRaised the frame after the stage entity is taken out of the group (picked).

Methods​

MemberWhat 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
MemberWhat 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: