コード例 #1
0
ファイル: ObjectPool.cs プロジェクト: MorozO2/BumRush
    /// <summary>
    /// Spawns a gameobject.
    /// </summary>
    /// <param name="pos">The position to spawn the gameobject.</param>
    /// <param name="rot">The rotation to spawn the gameobject.</param>
    /// <returns>The spawned gameobject.</returns>
    public GameObject Spawn(Vector3 pos, Quaternion rot)
    {
        GameObject com = null;

        if (DespawnedElements.Count != 0)
        {
            while (com == null && DespawnedElements.Count > 0)
            {
                com = DespawnedElements.Dequeue();
            }
            if (com == null)
            {
                com = Instantiate();
            }
        }
        else
        {
            com = Instantiate();
        }
        com.transform.position           = pos;
        com.transform.transform.rotation = rot;
        ActiveObject.Add(com);
        com.gameObject.SetActive(true);
        if (OnObjectSpawn != null)
        {
            OnObjectSpawn.Invoke(com, this);
        }
        return(com);
    }
コード例 #2
0
    public GameObject Spawn(Vector3 pos, Quaternion rot)
    {
        GameObject com = null;

        if (DespawnedElements.Count != 0)
        {
            com = DespawnedElements.Dequeue();
        }
        else
        {
            com = Instantiate();
        }
        com.transform.position           = pos;
        com.transform.transform.rotation = rot;
        ActiveObject.Add(com);
        com.gameObject.SetActive(true);
        return(com);
    }