Skip to main content

PotatoSapling

A class in Root.Township, the global namespace.

Server: a plant that spawns a random number of pullable crops (potatoes and the like) at set positions, and disposes of itself once all are pulled.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private DisposablePickup disposableDisposes the plant once empty.
private GrowerGroup growerGroupOptional group that grows crops over time.
private GrowthDefinition growthGrowth to plant at each position. Use this or prefab.
private int maximumMost crops to spawn (default 5).
private int minimumFewest crops to spawn (default 1).
private SpawnPositions positionsSpawn positions for the crops.
private NetworkPrefab prefabCrop prefab spawned directly when growth is not set.
private AnimationCurve probabilityCurveCurve that weights the crop count.
private PullPickupGroup pullPickupGroupGroup of crops that can be pulled out.

Methods​

MemberWhat it is
override void InitializeAsServer(SpawnData spawnData)Hooks the grower group and pull group, adds existing crops, and disposes at once if there are none.
protected override void Generate(SpawnData spawnData)At generation, spawns the picked number of crops.
7 private and internal methods
MemberWhat it is
private void AddPickup(Pickup pickup)Adds a grown pickup to the pull group.
private void CheckDispose()Disposes the plant if nothing is left to pull.
private int EvaluateCount()Picks a count between minimum and maximum, weighted by probabilityCurve.
private void PickupPulled(Pickup pickup)When the last crop is pulled, checks a frame later whether to dispose.
private void RemovePickup(Pickup pickup)Removes a pickup from the pull group.
private void Setup(NetworkEntity child, int index)Adds a spawned crop's pickup to the pull group.
private void SpawnChildren(SpawnData spawnData, int quantity)Spawns each crop as prefab or, if growth is set, adds it to the grower group to grow.