ㅇㅇㅇ

This commit is contained in:
dldydtn9755-crypto
2026-06-25 18:18:16 +09:00
parent ac043dd904
commit efd215b558
3 changed files with 68 additions and 68 deletions

View File

@@ -13,7 +13,6 @@ public class RandomSceneRouteManager : MonoBehaviour
[SerializeField] private string finalSceneName;
private readonly HashSet<string> visitedScenes = new HashSet<string>();
private bool finalSceneUsed = false;
private string nextSceneCode1 = "";
private string nextSceneCode2 = "";
@@ -26,6 +25,7 @@ private void Awake()
{
Instance = this;
DontDestroyOnLoad(gameObject);
SceneManager.sceneLoaded += OnSceneLoaded;
}
else
{
@@ -33,10 +33,28 @@ private void Awake()
}
}
private void OnDestroy()
{
if (Instance == this)
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
string sceneName = scene.name.Trim();
if (IsRoomScene(sceneName))
{
visitedScenes.Add(sceneName);
Debug.Log("현재 방 방문 처리: " + sceneName);
}
}
public void PrepareNextSceneChoices()
{
string currentSceneName = SceneManager.GetActiveScene().name;
Debug.Log("현재 씬 이름: " + currentSceneName);
string currentSceneName = SceneManager.GetActiveScene().name.Trim();
if (IsRoomScene(currentSceneName))
{
@@ -48,21 +66,17 @@ public void PrepareNextSceneChoices()
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);
}
@@ -85,15 +99,11 @@ public void PrepareNextSceneChoices()
nextSceneCode2 = candidates[1];
nextSceneName2 = GetDisplayName(nextSceneCode2);
}
else if (candidates.Count == 1 && !finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
{
nextSceneCode2 = finalSceneName.Trim();
nextSceneName2 = GetDisplayName(nextSceneCode2);
}
// 남은 방이 하나도 없으면 마지막 씬으로 보냄
if (candidates.Count == 0)
{
if (!finalSceneUsed && !string.IsNullOrWhiteSpace(finalSceneName))
if (!string.IsNullOrWhiteSpace(finalSceneName))
{
nextSceneCode1 = finalSceneName.Trim();
nextSceneName1 = GetDisplayName(nextSceneCode1);
@@ -104,6 +114,18 @@ public void PrepareNextSceneChoices()
}
}
// 남은 방이 하나뿐이면 1번은 남은 방, 2번은 마지막 씬으로 가능
if (candidates.Count == 1)
{
if (!string.IsNullOrWhiteSpace(finalSceneName))
{
nextSceneCode2 = finalSceneName.Trim();
nextSceneName2 = GetDisplayName(nextSceneCode2);
}
}
Debug.Log("현재 씬: " + currentSceneName);
Debug.Log("방문한 씬 수: " + visitedScenes.Count);
Debug.Log("¼±ÅÃÁö 1: " + nextSceneName1 + " / " + nextSceneCode1);
Debug.Log("¼±ÅÃÁö 2: " + nextSceneName2 + " / " + nextSceneCode2);
}
@@ -133,33 +155,45 @@ public string GetNextSceneName()
PrepareNextSceneChoices();
if (!string.IsNullOrEmpty(nextSceneCode1))
{
return nextSceneCode1;
}
return string.Empty;
}
public void MarkSceneVisited(string sceneName)
public void RequestRandomSceneChange()
{
if (string.IsNullOrWhiteSpace(sceneName))
string nextSceneName = GetNextSceneName();
if (string.IsNullOrEmpty(nextSceneName))
{
Debug.LogWarning("이동할 다음 씬 이름이 비어있습니다.");
return;
}
string cleanSceneName = sceneName.Trim();
SceneLoadManager loadManager = FindFirstObjectByType<SceneLoadManager>();
if (cleanSceneName == finalSceneName)
if (loadManager != null)
{
finalSceneUsed = true;
Debug.Log("랜덤 씬 이동 요청: " + nextSceneName);
loadManager.RequestSceneChange(nextSceneName);
}
if (IsRoomScene(cleanSceneName))
else
{
visitedScenes.Add(cleanSceneName);
Debug.LogWarning("SceneLoadManager가 없어서 바로 씬 이동합니다: " + nextSceneName);
SceneManager.LoadScene(nextSceneName);
}
}
Debug.Log("방문 처리된 씬: " + cleanSceneName);
public void ResetRoute()
{
visitedScenes.Clear();
nextSceneCode1 = "";
nextSceneCode2 = "";
nextSceneName1 = "";
nextSceneName2 = "";
Debug.Log("랜덤 방 방문 기록 초기화");
}
private void Shuffle(List<string> list)
@@ -189,6 +223,9 @@ private string GetDisplayName(string sceneName)
case "Cave_Test_2":
return "µ¿±¼¹æ";
case "Gepto first":
return "제페토";
default:
return sceneName;
}
@@ -199,49 +236,12 @@ private bool IsRoomScene(string sceneName)
foreach (string roomSceneName in roomSceneNames)
{
if (string.IsNullOrWhiteSpace(roomSceneName))
{
continue;
}
if (roomSceneName.Trim() == sceneName)
{
if (roomSceneName.Trim() == sceneName.Trim())
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;
nextSceneCode1 = "";
nextSceneCode2 = "";
nextSceneName1 = "";
nextSceneName2 = "";
Debug.Log("랜덤 방 방문 기록 초기화");
}
}