Skip to main content

InstancedPrefab

A class in Root.Township, the global namespace.

Simple pool of plain (non-networked) prefab instances, keyed by prefab. Used by forest fill to place and recycle objects.

Constructors​

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

Fields​

3 private and internal fields
MemberWhat it is
private GameObject gameObjectCached game object.
private static Dictionary<GameObject, Stack<InstancedPrefab>> instancesStatic pools of free instances per prefab.
private Transform transformCached transform.

Properties​

MemberWhat it is
GameObject Prefab { get; private set; }The prefab this instance came from, used as its pool key.

Methods​

MemberWhat it is
void Disable()Hides the instance and pushes it back onto its prefab's pool.
static InstancedPrefab Get(InstancedPrefab prefab)Pops a pooled instance of the prefab, or creates one (adding the component if needed). It comes back inactive or as instantiated.
static InstancedPrefab Get(GameObject prefab)Pops a pooled instance of the prefab, or creates one (adding the component if needed). It comes back inactive or as instantiated.
void Initialize(GameObject prefab)Stores the source prefab and caches the transform and game object.
void MoveAndEnable(Vector3 position, Quaternion rotation, Vector3 scale)Sets position, rotation and scale, then activates the instance.

Used in​

Members of other types that take, return or hold a InstancedPrefab: