Пример #1
0
    public void BuildTiles()
    {
        int size = Settings.maxDistance / (Settings.tileSize * 2);

        Vector3 center = new Vector3((int)playerSingleton.transform.position.x / Settings.tileSize, 0, (int)playerSingleton.transform.position.z / Settings.tileSize);

        Queue <Vector3> tileQue = new Queue <Vector3>();

        GameObject[] tiles = GameObject.FindGameObjectsWithTag("Tile");

        bool isFound;

        for (int x = (-size + (int)center.x); x <= (size + (int)center.x); x++)
        {
            for (int z = (-size + (int)center.z); z <= (size + (int)center.z); z++)
            {
                isFound = false;

                Vector3 tilePos = new Vector3(x * Settings.tileSize, 0, z * Settings.tileSize);

                foreach (Vector3 tile in builder.buildQue)
                {
                    if (tile == tilePos)
                    {
                        isFound = true;
                        break;
                    }
                }

                if (isFound)
                {
                    continue;
                }

                foreach (GameObject tile in tiles)
                {
                    if (tile.transform.position == tilePos)
                    {
                        isFound = true;
                        break;
                    }
                }

                if (!isFound)
                {
                    tileQue.Enqueue(tilePos);
                }
            }
        }

        builder.AddToBuildQueue(tileQue);
    }