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
Inherited Members
Namespace: UnityEngine .Perception.Randomization.Utilities
Assembly: Unity.Perception.Runtime.dll
Syntax
[MovedFrom("UnityEngine.Perception.Randomization.Randomizers.Utilities")]
public class GameObjectOneWayCache
Constructors
GameObjectOneWayCache(Transform, GameObject[], Randomizer)
Creates a new GameObjectOneWayCache
Declaration
public GameObjectOneWayCache(Transform parent, GameObject[] gameObjects, Randomizer randomizer)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | The parent object all cached instances will be parented under |
Game |
gameObjects | The gameObjects to cache |
Randomizer | randomizer | Randomizer that invoked the method |
Properties
ActiveCachedObjectsCount
The number of active cache objects in the scene
Declaration
public int ActiveCachedObjectsCount { get; }
Property Value
Type | Description |
---|---|
int |
Methods
GetOrInstantiate(int)
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 |
---|---|---|
int | index | The index of the gameObject to instantiate |
Returns
Type | Description |
---|---|
Game |
Exceptions
Type | Condition |
---|---|
Argument |
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 |
---|---|---|
Game |
gameObject |
Returns
Type | Description |
---|---|
Game |
Exceptions
Type | Condition |
---|---|
Argument |
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 |
---|---|
Game |
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 |
---|---|---|
Game |
gameObject | The object to make inactive |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when gameObject is not an active cached object. |