This commit is contained in:
unknown
2026-04-16 18:19:23 +05:00
parent 6c3f72385e
commit 087db550f1
43 changed files with 1676 additions and 58 deletions

View File

@@ -0,0 +1,65 @@
using UnityEngine;
/// <summary>
/// Генерирует плоский мир — слои блоков по всей сетке чанков.
/// Реализует простой интерфейс, который легко заменить на terrain-генератор.
/// </summary>
public class FlatWorldGenerator : MonoBehaviour
{
[Header("World Size (in chunks)")]
public int chunksX = 4;
public int chunksZ = 4;
[Header("Layers (bottom → top)")]
public LayerDef[] layers = new[]
{
new LayerDef { blockId = "stone", height = 3 },
new LayerDef { blockId = "dirt", height = 3 },
new LayerDef { blockId = "grass", height = 1 },
};
void Start()
{
if (WorldManager.Instance == null)
{
Debug.LogError("[FlatWorldGenerator] WorldManager not found.");
return;
}
Generate();
}
public void Generate()
{
for (int cx = 0; cx < chunksX; cx++)
for (int cz = 0; cz < chunksZ; cz++)
{
// Центрируем мир относительно нуля
var chunkPos = new Vector3Int(cx - chunksX / 2, 0, cz - chunksZ / 2);
var data = new ChunkData(chunkPos);
int currentY = 0;
foreach (var layer in layers)
{
for (int h = 0; h < layer.height; h++)
{
if (currentY >= ChunkData.HEIGHT) break;
for (int x = 0; x < ChunkData.SIZE; x++)
for (int z = 0; z < ChunkData.SIZE; z++)
data.SetBlock(x, currentY, z, layer.blockId);
currentY++;
}
}
WorldManager.Instance.CreateChunk(chunkPos, data);
}
Debug.Log($"[FlatWorldGenerator] Generated {chunksX * chunksZ} chunks.");
}
[System.Serializable]
public struct LayerDef
{
public string blockId;
[Min(1)] public int height;
}
}