Exemplo n.º 1
0
        public static MapSizeData CalculateMapCenterAndExtents(IEnumerable <Vector3Int> tiles, float yOffset = 0)
        {
            int minXOffset = int.MaxValue;
            int maxXOffset = int.MinValue;
            int minYOffset = int.MaxValue;
            int maxYOffset = int.MinValue;

            foreach (var coord in tiles)
            {
                Vector2Int offsetCoord = HexConverter.TileCoordToOffsetTileCoord(coord);
                if (offsetCoord.x < minXOffset)
                {
                    minXOffset = offsetCoord.x;
                }
                if (offsetCoord.x > maxXOffset)
                {
                    maxXOffset = offsetCoord.x;
                }
                if (offsetCoord.y < minYOffset)
                {
                    minYOffset = offsetCoord.y;
                }
                if (offsetCoord.y > maxYOffset)
                {
                    maxYOffset = offsetCoord.y;
                }
            }

            Vector3 worldMin = HexConverter.OffsetTileCoordToCartesianCoord(new Vector2Int(minXOffset, minYOffset));
            Vector3 worldMax = HexConverter.OffsetTileCoordToCartesianCoord(new Vector2Int(maxXOffset, maxYOffset));

            Vector3 center  = ((worldMin + worldMax) / 2);
            Vector3 extents = new Vector3((worldMax.x - worldMin.x) / 2f, 0, (worldMax.z - worldMin.z) / 2f);

            MapSizeData mapSizeData = new MapSizeData(minXOffset, maxXOffset, minYOffset, maxYOffset, center, extents);

            return(mapSizeData);
        }