docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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

    Inheritance
    object
    GameObjectOneWayCache
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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

    GameObject[] 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
    GameObject
    Exceptions
    Type Condition
    ArgumentException

    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
    Exceptions
    Type Condition
    ArgumentException

    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

    Exceptions
    Type Condition
    ArgumentException

    Thrown when gameObject is not an active cached object.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)