52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// 스토리 진행도(MainProgress)에 따라 다음 씬을 골라 전환한다.
|
|
// EventZoneTrigger / 대화 노드 이벤트 / 버튼 등에서 NextChapterScene()을 연결해 사용.
|
|
public class ChapterChanger : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public struct ChapterEntry
|
|
{
|
|
[Tooltip("진행도가 이 값 이상이면 이 씬으로 (조건을 만족하는 항목 중 가장 높은 것이 선택됨)")]
|
|
[Min(0)] public int MinProgress;
|
|
|
|
[Tooltip("전환할 씬 이름 (Build Settings에 등록돼 있어야 함)")]
|
|
public string SceneName;
|
|
}
|
|
|
|
[Tooltip("진행도 구간별 다음 씬. 예) 0→Chapter1, 3→Chapter2, 7→Chapter3 (순서는 상관없음)")]
|
|
[SerializeField] private List<ChapterEntry> _chapters = new();
|
|
|
|
// 현재 진행도에 맞는 씬을 골라 페이드 아웃과 함께 전환
|
|
// (시야/스카이박스 페이드와 로딩 화면은 SceneLoadManager가 처리)
|
|
public void NextChapterScene()
|
|
{
|
|
int progress = StoryManager.Instance != null ? StoryManager.Instance.MainProgress : 0;
|
|
|
|
string sceneName = ResolveScene(progress);
|
|
if (string.IsNullOrEmpty(sceneName))
|
|
{
|
|
Debug.LogWarning($"[ChapterChanger] 진행도 {progress}에 맞는 씬이 없음: {name}");
|
|
return;
|
|
}
|
|
|
|
SceneLoadManager.Instance.RequestSceneChange(sceneName);
|
|
}
|
|
|
|
// 진행도 이하의 MinProgress 중 가장 높은 항목의 씬 이름 (없으면 null)
|
|
private string ResolveScene(int progress)
|
|
{
|
|
string best = null;
|
|
int bestMin = int.MinValue;
|
|
foreach (var entry in _chapters)
|
|
{
|
|
if (string.IsNullOrEmpty(entry.SceneName)) continue;
|
|
if (entry.MinProgress > progress || entry.MinProgress < bestMin) continue;
|
|
bestMin = entry.MinProgress;
|
|
best = entry.SceneName;
|
|
}
|
|
return best;
|
|
}
|
|
}
|