Skip to content

API.Unity.Service.PrefabPool

JuDelCo edited this page Sep 23, 2022 · 3 revisions

Namespace: Ju.Services

IPrefabPoolService

This service handles pools of GameObjects / Components / Prefabs.

All pooled GameObjects will be inside an indestructible GameObject in the root managed by this service. All pooled objects will be destroyed automatically on service unload.

GameObject Spawn(GameObject prefab, Transform parent, Vector3 position, Quaternion rotation);
GameObject Spawn(GameObject prefab, Transform parent, Vector3 position);
GameObject Spawn(GameObject prefab, Transform parent);
GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation);
GameObject Spawn(GameObject prefab, Vector3 position);
GameObject Spawn(GameObject prefab);

T Spawn<T>(T prefabComponent, Transform parent, Vector3 position, Quaternion rotation) where T : Component;
T Spawn<T>(T prefabComponent, Transform parent, Vector3 position) where T : Component;
T Spawn<T>(T prefabComponent, Transform parent) where T : Component;
T Spawn<T>(T prefabComponent, Vector3 position, Quaternion rotation) where T : Component;
T Spawn<T>(T prefabComponent, Vector3 position) where T : Component;
T Spawn<T>(T prefabComponent) where T : Component;

void Recycle(GameObject target);
void Recycle<T>(T targetComponent) where T : Component;

int Count(GameObject prefab, bool includeActive = false);
int Count<T>(T prefabComponent, bool includeActive = false) where T : Component;

int CountAll(bool includeActive = false);

void SetCapacity(GameObject prefab, int capacity);
void SetCapacity<T>(T prefabComponent, int capacity) where T : Component;

void WarmupCapacity(Prefab prefab);
void WarmupCapacity<T>(T prefabComponent) where T : Component;

void Shrink(GameObject prefab, int maxSize, bool clearSpawned = false);
void Shrink<T>(T prefabComponent, int maxSize, bool clearSpawned = false) where T : Component;

void Clear(GameObject prefab, bool clearSpawned = false);
void Clear<T>(T prefabComponent, bool clearSpawned = false) where T : Component;

void ClearAll(bool clearSpawned = false);
Clone this wiki locally