Class GameObjectOneWayCache
Facilitates object pooling for a pre-specified collection of prefabs with the caveat that objects can be fetched from the cache but not returned. Every frame, the cache needs to be reset, which will return all objects to the pool
Namespace: UnityEngine.Perception.Randomization.Randomizers.Utilities
Syntax
public class GameObjectOneWayCache : object
Constructors
GameObjectOneWayCache(Transform, GameObject[])
Creates a new GameObjectOneWayCache
Declaration
public GameObjectOneWayCache(Transform parent, GameObject[] gameObjects)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parent | The parent object all cached instances will be parented under |
| GameObject[] | gameObjects | The gameObjects to cache |
Properties
NumObjectsActive
The number of active cache objects in the scene
Declaration
public int NumObjectsActive { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Methods
GetOrInstantiate(GameObject)
Retrieves an existing instance of the given gameObject from the cache if available. Otherwise, instantiate a new instance of the given gameObject.
Declaration
public GameObject GetOrInstantiate(GameObject gameObject)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject |
Returns
| Type | Description |
|---|---|
| GameObject |
GetOrInstantiate(Int32)
Retrieves an existing instance of the given gameObject from the cache if available. Otherwise, instantiate a new instance of the given gameObject.
Declaration
public GameObject GetOrInstantiate(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index | The index of the gameObject to instantiate |
Returns
| Type | Description |
|---|---|
| GameObject |
GetOrInstantiateRandomCachedObject()
Retrieves an existing instance of a random gameObject from the cache if available. Otherwise, instantiate a new instance of the random gameObject.
Declaration
public GameObject GetOrInstantiateRandomCachedObject()
Returns
| Type | Description |
|---|---|
| GameObject | A random cached GameObject |
ResetAllObjects()
Return all active cache objects back to an inactive state
Declaration
public void ResetAllObjects()
ResetObject(GameObject)
Returns the given cache object back to an inactive state
Declaration
public void ResetObject(GameObject gameObject)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The object to make inactive |