| | |
| | | public class GenerateTileMap : MonoBehaviour |
| | | { |
| | | public int? seed; |
| | | public int width = 256; |
| | | public int height = 256; |
| | | public int maxWidth = 256; |
| | | public int maxHeight = 384; |
| | | public int maxGroundHeight = 256; |
| | | private float scale; |
| | | private float offsetX; |
| | | private float offsetY; |
| | |
| | | |
| | | public IEnumerator GenerateTiles(Action finishedCallback, List<Vector3Int> destroyedTiles) |
| | | { |
| | | for (int x = 0; x < width; x++) |
| | | for (int x = 1; x < maxWidth; x++) |
| | | { |
| | | for (int y = 0; y < height; y++) |
| | | for (int y = 1; y < maxGroundHeight; y++) |
| | | { |
| | | float xPerlin = ((float)x / width) * scale + offsetX; |
| | | float yPerlin = ((float)y / height) * scale + offsetY; |
| | | float xPerlin = ((float)x / maxWidth) * scale + offsetX; |
| | | float yPerlin = ((float)y / maxHeight) * scale + offsetY; |
| | | float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin); |
| | | |
| | | if (perlinNoise >= 0.3f) |
| | |
| | | yield return null; |
| | | } |
| | | } |
| | | for (int x = 0; x <= maxWidth; x += maxWidth) |
| | | { |
| | | for (int y = 0; y <= maxHeight; y++) |
| | | { |
| | | tilemap.SetTile(new Vector3Int(x, y), borderTile); |
| | | } |
| | | |
| | | } |
| | | yield return null; |
| | | for (int y = 0; y <= maxHeight; y += maxHeight) |
| | | { |
| | | for (int x = 1; x <= maxWidth; x++) |
| | | { |
| | | tilemap.SetTile(new Vector3Int(x, y), borderTile); |
| | | } |
| | | |
| | | } |
| | | yield return null; |
| | | finishedCallback(); |
| | | } |
| | | } |