コード例 #1
0
    void SpawnSlot(Slot chosenSlot, int density)
    {
        //one side gets 2/3rds the other gets 1/3
        float d = (float)density;

        int sideADensity = Mathf.CeilToInt(d / 3f);

        int sideBDensity = (density - sideADensity);

        int maxSpawns = Mathf.Min(chosenSlot.left.GetMaxSpawns(), chosenSlot.right.GetMaxSpawns());

        if (sideBDensity > maxSpawns)
        {
            sideADensity += sideBDensity - maxSpawns;

            sideBDensity = maxSpawns;

            if (sideADensity > maxSpawns)
            {
                Debug.LogError("Too much density sent to slot");

                sideADensity = maxSpawns;
            }
        }

        GameObject[] spawnObjects = pool.AssignSlot(density);

        GameObject[] spawnA = spawnObjects.Take(sideADensity).ToArray();
        GameObject[] spawnB = spawnObjects.Skip(sideADensity).Take(sideBDensity).ToArray();

        // Debug.Log(spawnA.Length + " " + spawnB.Length);

        if (Random.value > 0.5f)
        {
            SpawnShelf(chosenSlot.left, spawnA, false);
            SpawnShelf(chosenSlot.right, spawnB, true);
        }
        else
        {
            SpawnShelf(chosenSlot.left, spawnB, false);
            SpawnShelf(chosenSlot.right, spawnA, true);
        }
    }