示例#1
0
    /// <summary>
    /// Gets next gameObject from the pool and set its position and rotation
    /// </summary>
    /// <param name="name"></param>
    /// <param name="position"></param>
    /// <param name="rotation></param>
    /// <returns></returns>
    public static GameObject GetNext(string name, Vector3 position, Quaternion rotation)
    {
        NPool pool = instance.GetPool(name);

        if (pool == null)
        {
            Debug.LogError("Pool with name " + name + " doesn't exist");
            return(null);
        }

        GameObject obj = pool.queue.Dequeue();

        obj.transform.position = position;
        obj.transform.rotation = rotation;
        obj.SetActive(true);
        pool.queue.Enqueue(obj);
        return(obj);
    }
示例#2
0
    /// <summary>
    /// Gets next gameObject from the pool
    /// </summary>
    /// <param name="name"></param>
    /// <param name="position"></param>
    /// <returns></returns>
    public static GameObject GetNext(string name)
    {
        if (instance == null)
        {
            instance = FindObjectOfType <NObjectPooler>();
            instance.Init();
        }

        NPool pool = instance.GetPool(name);

        if (pool == null)
        {
            Debug.LogError("Pool with name " + name + " doesn't exist");
            return(null);
        }

        GameObject obj = pool.queue.Dequeue();

        obj.SetActive(true);
        pool.queue.Enqueue(obj);
        return(obj);
    }