Exemplo n.º 1
0
        private GameObject[,] GenerateTiles()
        {
            GameObject[,] tiles = new GameObject[mapSize.x, mapSize.y];

            for (int y = 0; y < mapSize.y; ++y)
            {
                for (int x = 0; x < mapSize.x; ++x)
                {
                    // TODO - Deal with terrain randomization here

                    Vector2Int offsetCoordinates = new Vector2Int(x, y);
                    Vector3Int cubeCoordinates   = HexConversions.OffsetCoordToCubeCoord(offsetCoordinates);
                    Vector3    worldCoordinates  = HexConversions.OffsetCoordToWorldPosition(offsetCoordinates);

                    // Create the tile itself in the world view and assign its variables
                    GameObject tile = GameObject.Instantiate(tilePrefab);
                    tile.transform.SetParent(transform, true);
                    tile.transform.localPosition = worldCoordinates;
                    tile.name = cubeCoordinates.ToString();
                    ((Tile)tile.GetComponent(typeof(Tile))).cubeCoordinates = cubeCoordinates;

                    // Add generated tile to array
                    tiles[x, y] = tile;
                }
            }

            return(tiles);
        }
Exemplo n.º 2
0
        /// Returns all tiles which have a specific distance to the origin. Thickness goes inwards
        public static List <Vector3Int> GetRing(Vector3Int origin, int radius, int thickness)
        {
            //This is also not the most performant way to do it but again for almost all use cases it should be absolutely no issue.
            //If you happen to need a faster solution, again just precalculate the offets for each range once, store it in a list or dictionary and used that stored data
            List <Vector3Int> ring = new List <Vector3Int>();
            List <Vector2Int> allInManhattanrange = GetAllWithinManhattanRange(origin, radius, false);

            foreach (var v in allInManhattanrange)
            {
                if (Distance(origin, HexConversions.OffsetCoordToCubeCoord(v)) > radius - thickness)
                {
                    ring.Add(HexConversions.OffsetCoordToCubeCoord(v));
                }
            }

            return(ring);
        }