게이트 이동 시스템 추가 및 기존 이동 매니저 정리

This commit is contained in:
dldydtn9755-crypto
2026-06-22 11:28:53 +09:00
parent f443c4a4de
commit 6fc20431e8
57 changed files with 767 additions and 435 deletions

View File

@@ -0,0 +1,134 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RandomSceneRouteManager : MonoBehaviour
{
public static RandomSceneRouteManager Instance;
[Header("랜덤으로 이동할 방 Scene 이름들")]
[SerializeField] private string[] roomSceneNames;
[Header("모든 방 방문 후 이동할 마지막 Scene 이름")]
[SerializeField] private string finalSceneName;
private readonly HashSet<string> visitedScenes = new HashSet<string>();
private bool finalSceneUsed = false;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public string GetNextSceneName()
{
string currentSceneName = SceneManager.GetActiveScene().name;
Debug.Log("현재 씬 이름: " + currentSceneName);
if (IsRoomScene(currentSceneName))
{
visitedScenes.Add(currentSceneName);
}
List<string> candidates = new List<string>();
foreach (string sceneName in roomSceneNames)
{
if (string.IsNullOrWhiteSpace(sceneName))
{
continue;
}
string cleanSceneName = sceneName.Trim();
if (cleanSceneName == currentSceneName)
{
continue;
}
if (visitedScenes.Contains(cleanSceneName))
{
continue;
}
candidates.Add(cleanSceneName);
}
if (candidates.Count > 0)
{
int randomIndex = Random.Range(0, candidates.Count);
string selectedSceneName = candidates[randomIndex];
visitedScenes.Add(selectedSceneName);
Debug.Log("랜덤으로 선택된 다음 씬: " + selectedSceneName);
return selectedSceneName;
}
if (!finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
{
finalSceneUsed = true;
string cleanFinalSceneName = finalSceneName.Trim();
Debug.Log("모든 방 방문 완료. 마지막 씬으로 이동: " + cleanFinalSceneName);
return cleanFinalSceneName;
}
Debug.LogWarning("이동 가능한 다음 씬이 없습니다.");
return string.Empty;
}
private bool IsRoomScene(string sceneName)
{
foreach (string roomSceneName in roomSceneNames)
{
if (string.IsNullOrWhiteSpace(roomSceneName))
{
continue;
}
if (roomSceneName.Trim() == sceneName)
{
return true;
}
}
return false;
}
public void RequestRandomSceneChange()
{
if (SceneLoadManager.Instance == null)
{
Debug.LogError("SceneLoadManager가 없습니다.");
return;
}
string nextSceneName = GetNextSceneName();
if (string.IsNullOrEmpty(nextSceneName))
{
Debug.LogWarning("이동할 다음 씬 이름이 비어있습니다.");
return;
}
Debug.Log("랜덤 씬 이동 요청: " + nextSceneName);
SceneLoadManager.Instance.RequestSceneChange(nextSceneName);
}
public void ResetRoute()
{
visitedScenes.Clear();
finalSceneUsed = false;
Debug.Log("랜덤 방 방문 기록 초기화");
}
}