2026-11-05 12:11:10 +00:00
using TKS.OutGame ;
2026-11-03 19:10:10 +00:00
using UnityEngine ;
2026-11-05 12:11:10 +00:00
using UnityEngine.Serialization ;
2026-11-03 19:10:10 +00:00
namespace TKS
{
2026-11-05 12:11:10 +00:00
/// <summary>씬에 하나만 두면 카메라·전장·전투 관리자·HUD·입력·월드맵·아웃게임을 코드로 구성하고 본영 로비(없으면 첫 스테이지)로 시작한다.</summary>
2026-11-03 19:10:10 +00:00
public class GameBootstrap : MonoBehaviour
{
public BalanceConfig Config ;
public bool AutoStart = true ;
2026-11-05 12:11:10 +00:00
/// <summary>true = 시작 화면이 본영 로비(출정 → 챕터 월드맵 → 스테이지 팝업 → 전투 · 2026-11-05 #1093). false = 바로 StartStageIndex 전투.</summary>
[FormerlySerializedAs("StartOnWorldMap")]
public bool StartOnLobby = true ;
2026-11-03 19:10:10 +00:00
public int StartStageIndex = 0 ;
public BattleManager Battle { get ; private set ; }
2026-11-03 19:29:16 +00:00
public CameraController CameraCtrl { get ; private set ; }
2026-11-04 18:38:47 +00:00
public WorldMapScreen WorldMap { get ; private set ; }
2026-11-05 12:11:10 +00:00
public OutGameRoot OutGame { get ; private set ; }
2026-11-03 19:10:10 +00:00
void Awake ( )
{
if ( Config = = null ) Config = Resources . Load < BalanceConfig > ( "BalanceConfig" ) ;
if ( Config = = null )
{
Debug . LogError ( "[TKS] BalanceConfig 자산이 없습니다. 메뉴 TKS/Setup Project 를 실행하세요." ) ;
return ;
}
var cam = Camera . main ;
if ( cam = = null )
{
var cgo = new GameObject ( "Main Camera" ) ;
cgo . tag = "MainCamera" ;
cam = cgo . AddComponent < Camera > ( ) ;
}
cam . orthographic = true ;
cam . clearFlags = CameraClearFlags . SolidColor ;
cam . backgroundColor = new Color ( 0.07f , 0.09f , 0.11f ) ;
cam . transform . position = new Vector3 ( 0f , 0f , - 10f ) ;
cam . nearClipPlane = 0.1f ;
cam . farClipPlane = 100f ;
2026-11-04 04:05:46 +00:00
// 탑다운: 같은 정렬 순서의 스프라이트는 y 가 큰(멀리 있는) 유닛이 뒤에 그려진다
cam . transparencySortMode = TransparencySortMode . CustomAxis ;
cam . transparencySortAxis = Vector3 . up ;
2026-11-09 14:12:52 +00:00
// 깊이 텍스처(2026-11-09): WL 에서 옮겨 온 이펙트 셰이더(소프트 파티클 · Hyper Casual 등)가 _CameraDepthTexture 를 읽는다 —
// 빌트인 카메라는 기본으로 만들지 않아 그 이펙트가 안 보이거나 불투명 덩어리로 그려짐(URP 는 켜져 있음). 전장 = 투명 스프라이트뿐이라 깊이 패스에 그릴 것이 거의 없다.
cam . depthTextureMode | = DepthTextureMode . Depth ;
2026-11-03 19:10:10 +00:00
var board = new GameObject ( "Board" ) . AddComponent < Board > ( ) ;
2026-11-04 06:56:02 +00:00
board . Build ( Config . boardSize , Config . boardArt ) ;
2026-11-03 19:29:16 +00:00
CameraCtrl = cam . GetComponent < CameraController > ( ) ;
if ( CameraCtrl = = null ) CameraCtrl = cam . gameObject . AddComponent < CameraController > ( ) ;
CameraCtrl . Init ( board , Config . cameraViewHeight , Config . cameraMinViewHeight , Config . cameraMaxViewHeight ) ;
2026-11-03 19:10:10 +00:00
Battle = new GameObject ( "BattleManager" ) . AddComponent < BattleManager > ( ) ;
Battle . Configure ( Config , board ) ;
var hud = new GameObject ( "HUD" ) . AddComponent < BattleHUD > ( ) ;
2026-11-03 19:29:16 +00:00
hud . Build ( Battle , cam , CameraCtrl ) ;
2026-11-03 19:10:10 +00:00
Battle . Hud = hud ;
var input = new GameObject ( "SlingshotInput" ) . AddComponent < SlingshotInput > ( ) ;
2026-11-03 19:29:16 +00:00
input . Init ( Battle , cam , hud , CameraCtrl ) ;
2026-11-03 19:10:10 +00:00
Battle . Sling = input ;
2026-11-17 07:27:22 +00:00
TutorialDirector . Ensure ( Battle ) ; // 1장 학습 판 안내(전투 밖 편성 화면 안내도 여기서 · 개발 요청서 C5)
2026-11-03 19:10:10 +00:00
2026-11-03 19:29:16 +00:00
// 카메라 연동: 행동 중인 유닛 추적 · 아군 턴 시작 시 아군 쪽으로
var camCtrl = CameraCtrl ;
var battle = Battle ;
battle . UnitActing + = u = > camCtrl . Follow ( u . transform ) ;
battle . PhaseChanged + = phase = >
{
if ( phase = = BattlePhase . PlayerTurn ) camCtrl . FocusOn ( PlayerFocusPoint ( battle ) ) ;
else if ( phase = = BattlePhase . StageClear | | phase = = BattlePhase . Defeat ) camCtrl . StopFollow ( ) ;
} ;
battle . StageStarted + = ( ) = > camCtrl . SnapTo ( PlayerFocusPoint ( battle ) ) ;
2026-11-03 19:10:10 +00:00
2026-11-04 18:38:47 +00:00
WorldMap = new GameObject ( "WorldMap" ) . AddComponent < WorldMapScreen > ( ) ;
WorldMap . Build ( Battle , hud , input , cam ) ;
2026-11-05 12:11:10 +00:00
// 아웃게임(세이브 · 로비 · 영웅 · 편성 · 거래) — 출전 편성·보상·군량을 전투·월드맵에 연결
OutGame = new GameObject ( "OutGame" ) . AddComponent < OutGameRoot > ( ) ;
OutGame . Build ( Battle , hud , input , WorldMap , cam ) ;
2026-11-04 18:38:47 +00:00
if ( ! AutoStart ) return ;
2026-11-16 08:17:35 +00:00
// 시작 흐름(PD 2026-11-16 「타이틀 화면은 별도의 씬」): 스플래시(회사 CI) → CDN 확인·받기 → 타이틀 = Splash·Title 씬(OutGame/Boot/SplashBoot · TitleSceneBoot)
// 이 Battle 씬은 타이틀 누름 뒤(또는 에디터에서 이 씬을 바로 Play) = 바로 본영 로비
2026-11-24 10:08:19 +00:00
// 첫 실행(서장을 끝내지 않은 새 세이브 · 기기 세이브 모드 · PD 2026-11-24) = 로비 대신 인트로 → 서장 1막(연의 전기 화면을 거치지 않음 · OutGame/FirstFlow)
if ( StartOnLobby & & WorldMap . HasData )
{
if ( OutGame . Flow = = null | | ! OutGame . Flow . BootBegin ( ) ) OutGame . ShowLobby ( ) ;
}
2026-11-04 18:38:47 +00:00
else Battle . StartStage ( StartStageIndex ) ;
2026-11-03 19:10:10 +00:00
}
2026-11-03 19:29:16 +00:00
/// <summary>아군 무게중심에서 적 쪽으로 조금 올린 지점.</summary>
static Vector2 PlayerFocusPoint ( BattleManager battle )
2026-11-03 19:10:10 +00:00
{
2026-11-03 19:29:16 +00:00
var players = battle . AliveUnits ( Faction . Player ) ;
2026-11-19 09:05:17 +00:00
players . RemoveAll ( p = > p . Npc | | ScenarioEvent . Absent ( p ) ) ; // 구출 대상(학습 판) · 연출이 숨긴(아직 나타나지 않은) 유닛은 초점 계산에서 뺀다 — 조작하는 유닛이 화면 아래로 밀리지 않게(2026-11-19 PD 2막 「관우가 너무 위쪽」)
2026-11-03 19:29:16 +00:00
if ( players . Count = = 0 ) return Vector2 . zero ;
Vector2 sum = Vector2 . zero ;
foreach ( var p in players ) sum + = p . Position ;
2026-11-21 06:13:26 +00:00
return sum / players . Count + new Vector2 ( 0f , battle . Config . cameraViewHeight * battle . Config . cameraFocusAhead ) ; // 아군을 화면 아래쪽에(적 쪽을 넓게 · 값 = cameraFocusAhead · 그 전 0.2 고정)
2026-11-03 19:10:10 +00:00
}
}
}