Пример #1
0
        public CellWrapper GetCellFor(Vector3 position)
        {
            var cellLocation = Vector3Int.FloorToInt(position / Configs.CellSideSize);
            var cellName     = CellUtils.CreateCellName(cellLocation);

            if (cellsByName.ContainsKey(cellName))
            {
                return(cellsByName[cellName]);
            }

            return(null);
        }
Пример #2
0
        public void Generate()
        {
            var grid       = GetComponent <Grid>();
            var sideLength = (int)Math.Sqrt(Configs.WorldCellCount);

            var worldBounds = new BoundsInt(Vector3Int.zero, new Vector3Int(sideLength, sideLength, 1));
            var cellBounds  = new BoundsInt(Vector3Int.zero, Configs.CellDimensions);

            foreach (var worldPosition in worldBounds.allPositionsWithin)
            {
                if (worldPosition.z > 0)
                {
                    break;
                }

                var writer = new Writer();
                foreach (Transform child in grid.transform)
                {
                    foreach (var position in cellBounds.allPositionsWithin)
                    {
                        if (position.z > 0)
                        {
                            break;
                        }

                        writer.WriteTile(GenerateRandomTile(), position);
                    }

                    writer.WriteTileMap();
                }

                writer.Save(CellUtils.CreateCellName(worldPosition));
            }

            Debug.Log("Done mofo!");
        }