63 lines
1.9 KiB (Stored with Git LFS)
C#
63 lines
1.9 KiB (Stored with Git LFS)
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Sirenix.OdinInspector;
|
|
using Unity.Cinemachine;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace DDD
|
|
{
|
|
public enum CameraType
|
|
{
|
|
BaseCam = 0,
|
|
}
|
|
|
|
public class CameraManager : Singleton<CameraManager>
|
|
{
|
|
[ShowInInspector, ReadOnly]
|
|
private Dictionary<CameraType, CinemachineCamera> _cameraDict;
|
|
|
|
private CinemachineBrain _cinemachineBrain;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
|
|
_cinemachineBrain = GetComponent<CinemachineBrain>();
|
|
}
|
|
|
|
public void ChangeScene(string sceneName)
|
|
{
|
|
var foundCams = FindObjectsByType<CinemachineCamera>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
|
_cameraDict = new Dictionary<CameraType, CinemachineCamera>(foundCams.Length);
|
|
|
|
foreach (var cam in foundCams)
|
|
{
|
|
if (Enum.TryParse<CameraType>(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;
|
|
}
|
|
}
|
|
}
|
|
} |