diff --git a/Assets/Scripts/Mechanics/GameOptimizer.cs b/Assets/Scripts/Mechanics/GameOptimizer.cs index b5a8c02..32bbd28 100644 --- a/Assets/Scripts/Mechanics/GameOptimizer.cs +++ b/Assets/Scripts/Mechanics/GameOptimizer.cs @@ -80,7 +80,10 @@ namespace Platformer.Mechanics fgTilemap = foreground.GetComponent(); } - // BT47 — Level Tilemap의 공중 Tile (Player 시작 Y + 1.5 이상 영역) 영역 → Foreground 영역 자동 이동 + // BT48 — Level → Foreground 자동 분류 강화. 분류 조건 2종 결합: + // (a) 임계값 위 (worldY >= playerY + 1.5) = 공중 = 무조건 Foreground (BT47 호환) + // (b) 임계값 아래여도 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 8 tile 이하 = 작은 공중 발판 + // → 일반 지면(통상 10+ tile 가로) 잘못 분류 방지 + 첨부 이미지 같은 작은 발판 자동 분류 var levelGo = GameObject.Find("Level"); if (levelGo != null && fgTilemap != null) { @@ -89,9 +92,10 @@ namespace Platformer.Mechanics if (levelTilemap != null && player != null) { float playerY = player.transform.position.y; - float airThresholdY = playerY + 1.5f; // Player 시작 Y + 1.5 위 = 공중 발판 영역 + float airThresholdY = playerY + 1.5f; // Player 시작 Y + 1.5 위 = 공중 (BT47 호환) + const int MAX_PLATFORM_WIDTH = 8; var bounds = levelTilemap.cellBounds; - int moved = 0; + int movedHigh = 0, movedSmall = 0; for (int x = bounds.xMin; x <= bounds.xMax; x++) { for (int y = bounds.yMin; y <= bounds.yMax; y++) @@ -99,24 +103,50 @@ namespace Platformer.Mechanics var pos = new Vector3Int(x, y, 0); if (!levelTilemap.HasTile(pos)) continue; Vector3 worldPos = levelTilemap.CellToWorld(pos); - if (worldPos.y < airThresholdY) continue; // 지면·벽 영역 그대로 - // 공중 영역 Tile → Foreground 영역 영역 이동 + bool aboveThreshold = worldPos.y >= airThresholdY; + bool isSmallAir = !aboveThreshold && IsSmallAirPlatform(levelTilemap, pos, MAX_PLATFORM_WIDTH); + if (!aboveThreshold && !isSmallAir) continue; var tile = levelTilemap.GetTile(pos); fgTilemap.SetTile(pos, tile); fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite); levelTilemap.SetTile(pos, null); - moved++; + if (aboveThreshold) movedHigh++; + else movedSmall++; } } if (fgTc != null) fgTc.ProcessTilemapChanges(); var lvlTc = levelGo.GetComponent(); if (lvlTc != null) lvlTc.ProcessTilemapChanges(); - Debug.Log($"[BT47-MoveTiles] moved={moved} air tiles from Level (worldY>={airThresholdY:F2}) to Foreground"); + Debug.Log($"[BT48-MoveTiles] moved={movedHigh + movedSmall} (high={movedHigh} thresholdY={airThresholdY:F2} / smallAir={movedSmall} maxWidth={MAX_PLATFORM_WIDTH})"); } } - Debug.Log($"[BT47-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}"); - Debug.Log($"[BT47-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]"); + Debug.Log($"[BT48-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}"); + Debug.Log($"[BT48-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]"); + } + + /// + /// BT48 — 작은 공중 발판 판별. 위·아래 인접 Tile이 모두 빈 공간 + 가로 연속 길이 maxWidth 이하. + /// 일반 지면(통상 10+ tile 가로) 잘못 분류 방지. + /// + static bool IsSmallAirPlatform(UnityEngine.Tilemaps.Tilemap tm, Vector3Int pos, int maxWidth) + { + if (tm.HasTile(pos + Vector3Int.up)) return false; + if (tm.HasTile(pos + Vector3Int.down)) return false; + int width = 1; + for (int dx = 1; dx <= maxWidth; dx++) + { + if (!tm.HasTile(pos + new Vector3Int(dx, 0, 0))) break; + width++; + if (width > maxWidth) return false; + } + for (int dx = 1; dx <= maxWidth; dx++) + { + if (!tm.HasTile(pos + new Vector3Int(-dx, 0, 0))) break; + width++; + if (width > maxWidth) return false; + } + return width <= maxWidth; } } }