Change map

This commit is contained in:
Lucastaa
2026-05-08 08:56:47 +07:00
parent 0b4c323d0a
commit a5b985350a
131 changed files with 4933 additions and 194 deletions

View File

@@ -113,9 +113,9 @@ namespace Hallucinate.GameSetup.Maze
{
_currentGrid = grid;
_container = container;
grid.OnCellChanged += HandleCellChanged;
// Initial render
// ĐỪNG đăng ký cái này vội: grid.OnCellChanged += HandleCellChanged;
for (int z = 0; z < grid.Depth; z++)
{
for (int x = 0; x < grid.Width; x++)
@@ -123,6 +123,9 @@ namespace Hallucinate.GameSetup.Maze
UpdateCellVisual(x, z, grid.GetCell(x, z), false);
}
}
// ĐĂNG KÝ Ở ĐÂY: Sau khi đã vẽ xong hết rồi mới nghe ngóng thay đổi
grid.OnCellChanged += HandleCellChanged;
}
public void Clear()
@@ -164,15 +167,20 @@ namespace Hallucinate.GameSetup.Maze
{
Vector2Int pos = new Vector2Int(x, z);
// 1. DÙNG DestroyImmediate ĐỂ XÓA THẬT SỰ TRƯỚC KHI TẠO MỚI
if (_spawnedCells.TryGetValue(pos, out GameObject oldObj))
{
Destroy(oldObj);
if (oldObj != null)
{
DestroyImmediate(oldObj);
}
_spawnedCells.Remove(pos);
}
GameObject prefab = null;
Quaternion rotation = Quaternion.identity;
// Logic xét duyệt loại prefab
if (type == MazeCellType.Corridor || type == MazeCellType.Processing)
{
(prefab, rotation) = GetCorridorPrefabAndRotation(x, z);
@@ -185,7 +193,7 @@ namespace Hallucinate.GameSetup.Maze
if (prefab == null) return;
float safeScale = Mathf.Max(0.001f, visualProfile.scale);
float modelScaleMultiplier = 0.25f;
float modelScaleMultiplier = 0.167f;
Vector3 localPos = new Vector3(x * safeScale, 0, z * safeScale);