using System.Collections; // 컬렉션 기능을 사용할거에요 -> System.Collections를 using System.Collections.Generic; // 제네릭 컬렉션 기능을 사용할거에요 -> System.Collections.Generic을 using UnityEngine; // 유니티 엔진의 기본 기능을 불러올거에요 -> UnityEngine을 using UnityEngine.SceneManagement; // 씬 관리 기능을 사용할거에요 -> UnityEngine.SceneManagement를 public class SettingsManager : MonoBehaviour // 클래스를 선언할거에요 -> MonoBehaviour를 상속받는 SettingsManager를 { public static SettingsManager Instance; // 변수를 선언할거에요 -> 싱글톤 인스턴스인 Instance를 public int qualityIndex; // 변수를 선언할거에요 -> 그래픽 품질 인덱스를 qualityIndex에 public int resolutionIndex; // 변수를 선언할거에요 -> 해상도 인덱스를 resolutionIndex에 public bool isFullScreen; // 변수를 선언할거에요 -> 전체 화면 여부를 isFullScreen에 private Resolution[] allResolutions; // 배열을 선언할거에요 -> 지원하는 모든 해상도를 담을 allResolutions를 public Resolution[] FilteredResolutions { get; private set; } // 프로퍼티를 선언할거에요 -> 필터링된 해상도 목록을 외부에서 읽기만 가능하게 private readonly Vector2Int[] commonResolutions = // 배열을 초기화할거에요 -> 공통 해상도 목록을 읽기 전용으로 { new(1280, 720), new(1280, 768), new(1280, 800), new(1360, 768), new(1366, 768), new(1680, 1050), new(1920, 1080) }; private void Awake() // 함수를 실행할거에요 -> 스크립트 시작 시 Awake를 { Debug.Log("SettingsManager Awake: " + gameObject.name); // 로그를 출력할거에요 -> 매니저 시작 알림을 if (Instance != null) // 조건이 맞으면 실행할거에요 -> 이미 인스턴스가 존재한다면 { Destroy(gameObject); // 파괴할거에요 -> 중복된 이 오브젝트를 return; // 중단할거에요 -> 초기화 로직을 } Instance = this; // 값을 저장할거에요 -> 나 자신을 싱글톤 인스턴스에 DontDestroyOnLoad(gameObject); // 유지할거에요 -> 씬이 바뀌어도 파괴되지 않게 InitResolutions(); // 함수를 실행할거에요 -> 해상도 목록을 초기화하는 InitResolutions를 LoadSettings(); // 함수를 실행할거에요 -> 저장된 설정을 불러오는 LoadSettings를 // 🔥 추가 SyncResolutionIndexWithCurrentScreen(); // 함수를 실행할거에요 -> 현재 화면 해상도와 인덱스를 동기화하는 함수를 ApplySettings(); // 함수를 실행할거에요 -> 설정을 실제로 적용하는 ApplySettings를 } void InitResolutions() // 함수를 선언할거에요 -> 해상도 목록을 초기화하는 InitResolutions를 { allResolutions = Screen.resolutions; // 값을 가져올거에요 -> 모니터가 지원하는 모든 해상도를 var list = new System.Collections.Generic.List(); // 리스트를 생성할거에요 -> 해상도를 담을 임시 리스트를 foreach (var res in allResolutions) // 반복할거에요 -> 모든 해상도에 대해 { foreach (var common in commonResolutions) // 반복할거에요 -> 공통 해상도 목록과 비교하기 위해 { if (res.width == common.x && res.height == common.y) // 조건이 맞으면 실행할거에요 -> 가로세로가 공통 해상도와 일치한다면 { if (!list.Exists(r => r.width == res.width && r.height == res.height)) // 조건이 맞으면 실행할거에요 -> 리스트에 없는 해상도라면 (중복 방지) list.Add(res); // 추가할거에요 -> 리스트에 해당 해상도를 } } } FilteredResolutions = list.ToArray(); // 변환할거에요 -> 리스트를 배열로 바꿔서 FilteredResolutions에 } // ===== 적용 메서드 ===== public void SetQuality(int index) // 함수를 선언할거에요 -> 그래픽 품질을 설정하는 SetQuality를 { qualityIndex = index; // 값을 저장할거에요 -> 품질 인덱스를 QualitySettings.SetQualityLevel(index); // 설정을 바꿀거에요 -> 유니티 품질 설정을 해당 레벨로 PlayerPrefs.SetInt("Quality", index); // 저장할거에요 -> 품질 인덱스를 로컬 저장소에 } public void SetResolution(int index) // 함수를 선언할거에요 -> 해상도를 설정하는 SetResolution을 { resolutionIndex = index; // 값을 저장할거에요 -> 해상도 인덱스를 ApplyResolution(); // 함수를 실행할거에요 -> 해상도를 적용하는 ApplyResolution을 PlayerPrefs.SetInt("Resolution", index); // 저장할거에요 -> 해상도 인덱스를 로컬 저장소에 } public void SetFullScreen(bool full) // 함수를 선언할거에요 -> 전체 화면을 설정하는 SetFullScreen을 { isFullScreen = full; // 값을 저장할거에요 -> 전체 화면 여부를 Screen.fullScreenMode = full // 설정을 바꿀거에요 -> 화면 모드를 ? FullScreenMode.FullScreenWindow // 조건이 참이면 전체 화면 창 모드로 : FullScreenMode.Windowed; // 조건이 거짓이면 창 모드로 ApplyResolution(); // 함수를 실행할거에요 -> 해상도 적용 함수를 PlayerPrefs.SetInt("FullScreen", full ? 1 : 0); // 저장할거에요 -> 전체 화면 여부를 (1:참, 0:거짓) } void ApplyResolution() // 함수를 선언할거에요 -> 해상도를 실제 적용하는 ApplyResolution을 { var res = FilteredResolutions[resolutionIndex]; // 값을 가져올거에요 -> 선택된 해상도 정보를 Screen.SetResolution( // 설정을 바꿀거에요 -> 화면 해상도를 res.width, // 가로 크기로 res.height, // 세로 크기로 isFullScreen ? FullScreenMode.FullScreenWindow : FullScreenMode.Windowed // 화면 모드에 맞춰서 ); } void LoadSettings() // 함수를 선언할거에요 -> 저장된 설정을 불러오는 LoadSettings를 { qualityIndex = PlayerPrefs.GetInt("Quality", QualitySettings.names.Length - 1); // 불러올거에요 -> 품질 인덱스를 (없으면 최대값) resolutionIndex = PlayerPrefs.GetInt("Resolution", 0); // 불러올거에요 -> 해상도 인덱스를 (없으면 0) isFullScreen = PlayerPrefs.GetInt("FullScreen", 1) == 1; // 불러올거에요 -> 전체 화면 여부를 (없으면 1=참) } void ApplySettings() // 함수를 선언할거에요 -> 모든 설정을 적용하는 ApplySettings를 { SetQuality(qualityIndex); // 실행할거에요 -> 품질 설정을 Screen.fullScreenMode = isFullScreen // 설정을 바꿀거에요 -> 화면 모드를 ? FullScreenMode.FullScreenWindow // 조건이 참이면 전체 화면으로 : FullScreenMode.Windowed; // 조건이 거짓이면 창 모드로 ApplyResolution(); // 실행할거에요 -> 해상도 적용을 } void SyncResolutionIndexWithCurrentScreen() // 함수를 선언할거에요 -> 현재 화면과 해상도 인덱스를 맞추는 SyncResolutionIndexWithCurrentScreen을 { for (int i = 0; i < FilteredResolutions.Length; i++) // 반복할거에요 -> 필터링된 모든 해상도에 대해 { if (FilteredResolutions[i].width == Screen.width && // 조건이 맞으면 실행할거에요 -> 너비가 현재 화면과 같고 FilteredResolutions[i].height == Screen.height) // 높이가 현재 화면과 같다면 { resolutionIndex = i; // 값을 저장할거에요 -> 해당 인덱스를 return; // 중단할거에요 -> 함수를 (찾았으니까) } } } private void OnEnable() // 함수를 실행할거에요 -> 오브젝트 활성화 시 OnEnable을 { SceneManager.sceneLoaded += OnSceneLoaded; // 구독할거에요 -> 씬 로드 이벤트를 } private void OnDisable() // 함수를 실행할거에요 -> 오브젝트 비활성화 시 OnDisable을 { SceneManager.sceneLoaded -= OnSceneLoaded; // 구독 해제할거에요 -> 씬 로드 이벤트를 } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) // 함수를 선언할거에요 -> 씬 로드 완료 시 호출될 OnSceneLoaded를 { ApplySettings(); // 🔥 씬 로드 직후 다시 적용 // 실행할거에요 -> 설정 적용 함수를 } }