using UnityEngine;
using UnityEngine.Tilemaps;
namespace Platformer.Mechanics
{
///
/// 게임 시작 시 프레임·렌더·물리 영역 기본 최적화 + One-Way Platform 자동 적용.
/// PD 지시 2026-05-07 — 스크롤 버벅임 보완 + 점프·이동 시 지형 통과(One-Way Platform).
///
public static class GameOptimizer
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Init()
{
Application.targetFrameRate = 60;
QualitySettings.vSyncCount = 0;
Time.fixedDeltaTime = 1f / 60f;
// BT5-Dev #22 — Layer 영역 분리: Player(13) ↔ Enemy(14) 충돌 영구 OFF.
// IgnoreCollision 영역 instance 의존 X = 모든 Player·Enemy 영역 자동 통과 영역.
Physics2D.IgnoreLayerCollision(13, 14, true);
Debug.Log($"[BT22-LayerSep] Player(13) ↔ Enemy(14) collision OFF");
}
///
/// PD 지시 2026-05-07 — 모든 지형 Collider2D를 One-Way Platform으로 자동 변환.
/// 위에서만 착지·측면·아래 통과. Player·Enemy·DeathZone·VictoryZone·TokenInstance·Trigger Collider 영역 제외.
///
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
static void SetupOneWayPlatforms()
{
int applied = 0;
int excludedTrigger = 0, excludedActor = 0;
var allColliders = Object.FindObjectsByType(FindObjectsSortMode.None);
var appliedNames = new System.Collections.Generic.List();
var excludedNames = new System.Collections.Generic.List();
foreach (var c in allColliders)
{
if (c == null) continue;
if (c.isTrigger) { excludedTrigger++; continue; }
if (c.GetComponent() != null
|| c.GetComponent() != null
|| c.GetComponent() != null
|| c.GetComponent() != null
|| c.GetComponent() != null
|| c.GetComponent() != null)
{
excludedActor++;
continue;
}
c.usedByEffector = true;
var effector = c.GetComponent();
if (effector == null) effector = c.gameObject.AddComponent();
effector.useOneWay = true;
effector.surfaceArc = 180f;
effector.rotationalOffset = 0f;
effector.useSideFriction = false;
effector.useSideBounce = false;
applied++;
if (appliedNames.Count < 8) appliedNames.Add($"{c.gameObject.name}({c.GetType().Name})");
}
Debug.Log($"[BT21-OneWay] applied={applied} trigger={excludedTrigger} actor={excludedActor} total={allColliders.Length}");
Debug.Log($"[BT21-OneWay] appliedSamples=[{string.Join(", ", appliedNames)}]");
}
}
}