diff --git a/Assets/Scripts/Mechanics/GameOptimizer.cs b/Assets/Scripts/Mechanics/GameOptimizer.cs index d01a6a3..1ef373d 100644 --- a/Assets/Scripts/Mechanics/GameOptimizer.cs +++ b/Assets/Scripts/Mechanics/GameOptimizer.cs @@ -68,27 +68,29 @@ namespace Platformer.Mechanics if (appliedNames.Count < 8) appliedNames.Add($"{c.gameObject.name}({c.GetType().Name})"); } - // BT55 — PD 명시 (2026-05-07): "발판은 위에 설 수 있어야 해" - // BT54 폐기 (Foreground TilemapCollider 자동 부착 회복) → Drop-Through 패턴 (발판 위 착지) 보존. - // Foreground TilemapCollider2D 자동 부착 + Layer 16 + ContactFilter 동적 mask (PlayerController.cs 보유). + // BT59 — PD 명시 (2026-05-07): "BT49 정정 시점에서 Foreground에 충돌체크만 없애면 될거 같은데?" + // BT49 자동 분류 영역 회귀 (commit 9adfc64) + Foreground TilemapCollider 제거 (BT54 영역 결합). + // 결과: + // - Foreground Tilemap = 시각만 (TilemapRenderer + Layer 16). TilemapCollider 부착 X = 충돌 X + // - 자동 분류 영역(BT48 임계값+작은 발판)은 SetTile만 작동·ProcessTilemapChanges 호출은 fgTc null로 skip + // - Level Tilemap = 영구 충돌 (발판·지면 역할) var foreground = GameObject.Find("Foreground"); UnityEngine.Tilemaps.Tilemap fgTilemap = null; UnityEngine.Tilemaps.TilemapCollider2D fgTc = null; if (foreground != null) { - fgTc = foreground.GetComponent(); - if (fgTc == null) fgTc = foreground.AddComponent(); foreground.layer = 16; + // 기존 TilemapCollider2D 제거 (PD 명시 — Foreground 충돌 X) + var existingFgTc = foreground.GetComponent(); + if (existingFgTc != null) Object.Destroy(existingFgTc); fgTilemap = foreground.GetComponent(); + // fgTc null 유지 = 사후 복원 영역(if fgTilemap!=null && fgTc!=null) 자동 skip } - // BT55 — PD 명시 (2026-05-07): "이전 버전처럼 발판을 통과해서 이동하거나 점프할 수 있도록 되돌려" - // BT47 정확 회귀: 임계값(worldY >= playerY+1.5) 분류 + Sprite 강제 + BT49 None 차단. - // 폐기: BT48 작은 발판 휴리스틱 / BT50 Grid→Sprite 강제(이동 시) / BT52 TileFloating* 단일 / BT53 카탈로그 8종. - // 결과: BT47 정상 시점(moved=1389)과 동등한 자동 분류 + Drop-Through 패턴 회복. - // - 발판 위 착지 ✅ (Foreground TilemapCollider 부착·BT55 §72) - // - 점프 ascending 통과 ✅ (PlayerController.cs UpdateContactFilterForDropThrough) - // - 나무·plant·fence·house 자체 통과 ✅ (BT49 None 차단·Tile 자체 None Collider) + // 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) { @@ -97,9 +99,10 @@ namespace Platformer.Mechanics if (levelTilemap != null && player != null) { float playerY = player.transform.position.y; - float airThresholdY = playerY + 1.5f; // BT47 임계값 + 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++) @@ -107,36 +110,36 @@ namespace Platformer.Mechanics var pos = new Vector3Int(x, y, 0); if (!levelTilemap.HasTile(pos)) continue; - // BT49 None 차단 — 배경 의도 (tree·plant·fence·house) Foreground 이동 X + // BT49 — Tile asset의 m_ColliderType=None = 배경 의도 (예: tree·cloud) = 자동 분류 제외 var tileAsset = levelTilemap.GetTile(pos); if (tileAsset != null && tileAsset.colliderType == UnityEngine.Tilemaps.Tile.ColliderType.None) continue; - // BT47 임계값 분류 — 임계값 위 영역만 Foreground 이동 Vector3 worldPos = levelTilemap.CellToWorld(pos); - if (worldPos.y < airThresholdY) continue; - + bool aboveThreshold = worldPos.y >= airThresholdY; + bool isSmallAir = !aboveThreshold && IsSmallAirPlatform(levelTilemap, pos, MAX_PLATFORM_WIDTH); + if (!aboveThreshold && !isSmallAir) continue; var tile = levelTilemap.GetTile(pos); + // BT49 — Foreground 이동 시 Tile asset 원래 colliderType 존중 (None=배경, Sprite=발판) + var srcColliderType = (tileAsset != null) ? tileAsset.colliderType : UnityEngine.Tilemaps.Tile.ColliderType.Sprite; fgTilemap.SetTile(pos, tile); - fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.Sprite); // BT47 Sprite 강제 + fgTilemap.SetColliderType(pos, srcColliderType); 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($"[BT55-MoveTiles] moved={moved} (BT47 임계값 회귀·Sprite 강제·BT49 None 차단·thresholdY={airThresholdY:F2})"); + Debug.Log($"[BT48-MoveTiles] moved={movedHigh + movedSmall} (high={movedHigh} thresholdY={airThresholdY:F2} / smallAir={movedSmall} maxWidth={MAX_PLATFORM_WIDTH})"); } } // BT49 — Foreground Tilemap 자체에 이미 그려진 배경 Tile (예: tree·cloud — Tile asset colliderType=None) ColliderType=None 복원 // BT47이 SetColliderType(Sprite) 무차별 강제 → 배경 Tile도 발판처럼 충돌 → Tile asset metadata 존중으로 정정 - // BT51 — 사후 복원: None Tile만 SetColliderType(None) 복원 (배경 통과 보장). - // BT50의 Grid→Sprite 강제는 폐기 (PD가 직접 Foreground에 그린 Grid Tile의 default Collider 형상 보존). - // 이동 시 Grid→Sprite 강제(상단)는 유지 — Level→Foreground 이동되는 신규 Tile만 Sprite Collider 적용. if (fgTilemap != null && fgTc != null) { - int restoredNone = 0; + int restored = 0; var fgBounds = fgTilemap.cellBounds; for (int x = fgBounds.xMin; x <= fgBounds.xMax; x++) { @@ -149,19 +152,40 @@ namespace Platformer.Mechanics if (fgTileAsset.colliderType == UnityEngine.Tilemaps.Tile.ColliderType.None) { fgTilemap.SetColliderType(pos, UnityEngine.Tilemaps.Tile.ColliderType.None); - restoredNone++; + restored++; } } } - if (restoredNone > 0) fgTc.ProcessTilemapChanges(); - Debug.Log($"[BT51-FgRefine] colliderType=None restored: {restoredNone} (배경 통과·Grid Tile은 default Collider 유지)"); + if (restored > 0) fgTc.ProcessTilemapChanges(); + Debug.Log($"[BT49-Background] Foreground tile colliderType=None restored: {restored} (배경 Tile 충돌 차단)"); } Debug.Log($"[BT48-DropThrough] Layer16 applied={applied} levelKeptLayer0={levelKept} excluded={excluded} total={allColliders.Length}"); Debug.Log($"[BT48-DropThrough] appliedSamples=[{string.Join(", ", appliedNames)}]"); } - // BT52-A — IsSmallAirPlatform 헬퍼 폐기 (BT48 휴리스틱 알고리즘 폐기에 따른 dead code 제거). - // 새 알고리즘은 Tile asset 이름 매칭만 사용 — 헬퍼 불요. + /// + /// 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; + } } }