コード例 #1
0
    private static GameObject SpawnInternal(string name)
    {
        GameObjectPool pool = null;

        if (m_instance.m_goPools.TryGetValue(name, out pool))
        {
            var go = pool.Create();
            if (go != null)
            {
                goPoolsByObject.Add(go, pool);
            }
            return(go);
        }

        return(null);
    }
コード例 #2
0
    /// <summary>
    /// <para>The object will be despawned automatically after the specified lifetime and after particle death (if true). </para>
    /// </summary>
    public static GameObject Spawn(string name, Vector3 position, Quaternion rotation, float lifetimeInSeconds, bool waitForParticleDeath = true)
    {
        GameObjectPool pool = null;

        if (goPools.TryGetValue(name, out pool))
        {
            var go = pool.Create();
            go.transform.position = position;
            go.transform.rotation = rotation;
            pool.Free(go, lifetimeInSeconds, waitForParticleDeath);
            return(go);
        }

        Debug.Assert(pool != null, "There is no pool for " + name + ". Make sure to create one first.");
        return(null);
    }
コード例 #3
0
    /// <summary>
    /// <para>Make sure to call DeSpawn if the object isn't needed anymore. </para>
    /// </summary>
    public static GameObject Spawn(string name, Vector3 position, Quaternion rotation)
    {
        GameObjectPool pool = null;

        if (goPools.TryGetValue(name, out pool))
        {
            var go = pool.Create();
            go.transform.position = position;
            go.transform.rotation = rotation;
            goPoolsByObject.Add(go, pool);
            return(go);
        }

        Debug.Assert(pool != null, "There is no pool for " + name + ". Make sure to create one first.");
        return(null);
    }
コード例 #4
0
    /// <summary>
    /// <para>Make sure to call DeSpawn if the object isn't needed anymore. </para>
    /// </summary>
    public static GameObject Spawn(GameObject prefab)
    {
        Debug.Assert(prefab, "The requested prefab is null.");
        GameObject go = SpawnInternal(prefab.name);

        if (go == null)
        {
            // Create a pool for the prefab
            Debug.Log("Consider preloading the pool of objects for " + prefab.name + ".");
            var pool = new GameObjectPool(prefab, m_instance.m_defaultPreloadSize);

            if (m_instance.m_poolsGameObject)
            {
                pool.gameObject.transform.parent = m_instance.m_poolsGameObject.transform;
            }

            goPools.Add(prefab.name, pool);

            go = pool.Create();
            goPoolsByObject.Add(go, pool);
        }

        return(go);
    }
コード例 #5
0
 public GameObject Create(GameObject parent = null)
 {
     init();
     return(pool.Create(parent));
 }