コード例 #1
0
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    IEnumerator ObjSpawn()
    {
        while (true)
        {
            //--------------

            yield return(delay0);

            // SimplePool.GiveObj() - pool gives object.
            // Instead of using - GameObject obj = Instantiate(Object).
            // SimplePool.GiveObj(numElement)-> numElement - number of the item in editor (SimplePool).
            GameObject obj = SimplePool.GiveObj(Random.Range(0, SimplePool.numObjectsList));

            if (obj != null) // Checking that the pool is not empty.
            {
                obj.transform.SetPositionAndRotation(thisTransform.position, Random.rotation);
                obj.transform.parent = thisTransform;

                // After all the transformations of the object, activate it.
                obj.SetActive(true);

                yield return(delay1);

                //--------------

                // SimplePool.Takeobj() - object is returned to the pool. Instead of using - Destroy(Object).
                // SimplePool.Takeobj(GameObject)-> GameObject - is an object that to be returned to the pool.
                SimplePool.Takeobj(obj);
            }

            //--------------
        }
    }
コード例 #2
0
ファイル: MultiSpawn.cs プロジェクト: nvjob/simple-pool
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    IEnumerator ObjSpawn()
    {
        //--------------

        while (true)
        {
            yield return(delay0);

            thisTransform.rotation = Random.rotation;

            for (int z = 0; z < amountObj; z++)
            {
                for (int y = 0; y < amountObj; y++)
                {
                    for (int x = 0; x < amountObj; x++)
                    {
                        yield return(null);

                        int randomObj = Random.Range(0, SimplePool.numObjectsList);

                        // SimplePool.GiveObj() - pool gives object.
                        // Instead of using - GameObject obj = Instantiate(Object).
                        // SimplePool.GiveObj(numElement)-> numElement - number of the item in editor (SimplePool).
                        GameObject obj = SimplePool.GiveObj(randomObj);

                        if (obj != null) // Checking that the pool is not empty.
                        {
                            obj.transform.SetPositionAndRotation(thisTransform.position, Random.rotation);
                            obj.transform.parent     = thisTransform;
                            obj.transform.localScale = Vector3.one * objPoolScale / crackScale;
                            float st = objPoolScale * 0.5f - 0.5f;
                            float ot = objPoolScale * crackScale;
                            obj.transform.localPosition = new Vector3(st + x * ot, st + y * ot, st + z * ot);
                            childList.Add(obj);

                            // After all the transformations of the object, activate it.
                            obj.SetActive(true);
                        }
                    }
                }
            }

            yield return(delay0);

            for (int n = 0; n < childList.Count; n++)
            {
                yield return(null);

                // SimplePool.Takeobj() - object is returned to the pool. Instead of using - Destroy(Object).
                // SimplePool.Takeobj(GameObject)-> GameObject - is an object that to be returned to the pool.
                SimplePool.Takeobj(childList[n]);
            }

            childList = new List <GameObject>();
        }

        //--------------
    }
コード例 #3
0
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    IEnumerator RandomSpawn()
    {
        //--------------

        yield return(new WaitForSeconds(1.0f));

        while (true)
        {
            int randomObj = Random.Range(0, SimplePool.numObjectsList);
            if (SimplePool.GiveObj(randomObj) != null)
            {
                GameObject obj   = SimplePool.GiveObj(randomObj);
                Transform  trObj = obj.transform;
                trObj.position = new Vector3(movx + 12, trObj.position.y, trObj.position.z);
                obj.SetActive(true);
            }

            yield return(new WaitForSeconds(Random.Range(1, 5)));
        }

        //--------------
    }