示例#1
0
    private BoundsInt CalculateBounds()
    {
        int xMin = 0, yMin = 0, xMax = 0, yMax = 0;

        foreach (KeyValuePair <string, Tilemap> entry in tilemaps)
        {
            BoundsInt currBounds = entry.Value.cellBounds;
            if (!currBounds.size.Equals(new Vector3Int(0, 0, 1)))
            {
                if (currBounds.xMin < xMin)
                {
                    xMin = currBounds.xMin;
                }
                if (currBounds.yMin < yMin)
                {
                    yMin = currBounds.yMin;
                }
                if (currBounds.xMax > xMax)
                {
                    xMax = currBounds.xMax;
                }
                if (currBounds.yMax > yMax)
                {
                    yMax = currBounds.yMax;
                }
            }
        }

        int i = 0;

        while (xMax - xMin < 34)
        {
            if (i % 2 == 0)
            {
                xMax++;
            }
            else
            {
                xMin--;
            }
            i++;
        }
        i = 0;
        while (yMax - yMin < 17)
        {
            if (i % 2 == 0)
            {
                yMax++;
            }
            else
            {
                yMin--;
            }
            i++;
        }

        camBoundsRect.GetComponent <RectDraw>().Draw(
            new Vector3(xMin + 0.5f, yMin + 0.5f, 0),
            new Vector3(xMax - 1.5f, yMax - 1.5f, 0));

        BoundsInt output = new BoundsInt(xMin, yMin, 0, xMax - xMin, yMax - yMin, 0);

        Vector3[] spawnLocations = { Vector3.up, Vector3.down, Vector3.left, Vector3.right };
        for (int spawn = 0; spawn < spawnLocations.Length; spawn++)
        {
            Vector3[] spawnData = GetSpawn(spawnLocations[spawn], output);
            spawns.UpdatePosition(spawnLocations[spawn], spawnData[0]);
            exits.UpdatePosition(spawnLocations[spawn], GetExitPosition(spawnLocations[spawn], output));
            exits.UpdateScale(spawnLocations[spawn], GetExitScale(spawnLocations[spawn], output));
            gates.UpdatePosition(spawnLocations[spawn], spawnData[0]);
            gates.UpdateLength(spawnLocations[spawn], spawnData[1]);
        }

        if (totalBounds != output)
        {
            totalBounds = output;
            UpdateAllTiles();
        }
        return(output);
    }