using System; using System.Collections.Generic; using System.Threading.Tasks; using Sirenix.OdinInspector; using Unity.Cinemachine; using UnityEngine; namespace DDD { public enum CameraType { BaseCam = 0, } public class CameraManager : Singleton { [ShowInInspector, ReadOnly] private Dictionary _cameraDict; private CinemachineBrain _cinemachineBrain; protected override void OnAwake() { base.OnAwake(); _cinemachineBrain = GetComponent(); } public void ChangeScene(string sceneName) { var foundCams = FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None); _cameraDict = new Dictionary(foundCams.Length); foreach (var cam in foundCams) { if (Enum.TryParse(cam.name, out var type)) { if (!_cameraDict.TryAdd(type, cam)) Debug.LogWarning($"중복된 CameraType: {type}"); } else { Debug.LogWarning($"Enum에 없는 카메라 이름: {cam.name}"); } } if (sceneName == "01.Restaurant") { SwitchCamera(CameraType.BaseCam); } } public void SwitchCamera(CameraType cameraType, CinemachineBlendDefinition.Styles blendStyle = CinemachineBlendDefinition.Styles.Cut, float blendDuration = 1f) { _cinemachineBrain.DefaultBlend = new CinemachineBlendDefinition(blendStyle, blendDuration); foreach (var pair in _cameraDict) { pair.Value.Priority = (pair.Key == cameraType) ? 10 : 0; } } } }