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 visitedScenes = new HashSet(); private bool finalSceneUsed = false; private string nextSceneCode1 = ""; private string nextSceneCode2 = ""; private string nextSceneName1 = ""; private string nextSceneName2 = ""; private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } public void PrepareNextSceneChoices() { string currentSceneName = SceneManager.GetActiveScene().name; Debug.Log("ÇöÀç ¾À À̸§: " + currentSceneName); if (IsRoomScene(currentSceneName)) { visitedScenes.Add(currentSceneName); } List candidates = new List(); 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); } Shuffle(candidates); nextSceneCode1 = ""; nextSceneCode2 = ""; nextSceneName1 = ""; nextSceneName2 = ""; if (candidates.Count >= 1) { nextSceneCode1 = candidates[0]; nextSceneName1 = GetDisplayName(nextSceneCode1); } if (candidates.Count >= 2) { 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)) { nextSceneCode1 = finalSceneName.Trim(); nextSceneName1 = GetDisplayName(nextSceneCode1); } else { Debug.LogWarning("À̵¿ °¡´ÉÇÑ ´ÙÀ½ ¾ÀÀÌ ¾ø½À´Ï´Ù."); } } Debug.Log("¼±ÅÃÁö 1: " + nextSceneName1 + " / " + nextSceneCode1); Debug.Log("¼±ÅÃÁö 2: " + nextSceneName2 + " / " + nextSceneCode2); } public string GetNextSceneName1() { return nextSceneName1; } public string GetNextSceneCode1() { return nextSceneCode1; } public string GetNextSceneName2() { return nextSceneName2; } public string GetNextSceneCode2() { return nextSceneCode2; } public string GetNextSceneName() { PrepareNextSceneChoices(); if (!string.IsNullOrEmpty(nextSceneCode1)) { return nextSceneCode1; } return string.Empty; } public void MarkSceneVisited(string sceneName) { if (string.IsNullOrWhiteSpace(sceneName)) { return; } string cleanSceneName = sceneName.Trim(); if (cleanSceneName == finalSceneName) { finalSceneUsed = true; } if (IsRoomScene(cleanSceneName)) { visitedScenes.Add(cleanSceneName); } Debug.Log("¹æ¹® ó¸®µÈ ¾À: " + cleanSceneName); } private void Shuffle(List list) { for (int i = 0; i < list.Count; i++) { int randomIndex = Random.Range(i, list.Count); string temp = list[i]; list[i] = list[randomIndex]; list[randomIndex] = temp; } } private string GetDisplayName(string sceneName) { switch (sceneName) { case "blackjack": return "ºí·¢Àè"; case "CatsRoom": return "Ĺ·ë"; case "MazeRoom": return "¹Ì·Î¹æ"; case "Cave_Test_2": return "µ¿±¼¹æ"; default: return sceneName; } } 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; nextSceneCode1 = ""; nextSceneCode2 = ""; nextSceneName1 = ""; nextSceneName2 = ""; Debug.Log("·£´ý ¹æ ¹æ¹® ±â·Ï ÃʱâÈ­"); } }