150 lines
3.9 KiB
C#
150 lines
3.9 KiB
C#
|
using System.Collections;
|
||
|
using BlueWater.Utility;
|
||
|
using Sirenix.OdinInspector;
|
||
|
using Unity.Cinemachine;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Rendering;
|
||
|
using UnityEngine.Rendering.Universal;
|
||
|
|
||
|
namespace BlueWater
|
||
|
{
|
||
|
public class CombatCameraManager : Singleton<CombatCameraManager>
|
||
|
{
|
||
|
// Components
|
||
|
#region Components
|
||
|
|
||
|
[Title("카메라")]
|
||
|
[SerializeField]
|
||
|
private Transform _cinemachineCameras;
|
||
|
|
||
|
[field: SerializeField]
|
||
|
public CinemachineCamera BaseCombatCamera { get; private set; }
|
||
|
|
||
|
public Camera MainCamera;
|
||
|
|
||
|
// Variables
|
||
|
private Vignette _vignette;
|
||
|
private Coroutine _lowHpVignetteCoroutine;
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
// Unity events
|
||
|
#region Unity events
|
||
|
|
||
|
protected override void OnAwake()
|
||
|
{
|
||
|
Initialize();
|
||
|
}
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
if (!GameManager.Instance) return;
|
||
|
|
||
|
GameManager.Instance.OnInstantiateCombatPlayer += SetFollow;
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
if (!GameManager.Instance) return;
|
||
|
|
||
|
GameManager.Instance.OnInstantiateCombatPlayer -= SetFollow;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
// Initialize methods
|
||
|
#region Initialize methods
|
||
|
|
||
|
private void Initialize()
|
||
|
{
|
||
|
_cinemachineCameras = GameObject.Find("CinemachineCameras").transform;
|
||
|
BaseCombatCamera = _cinemachineCameras.Find("BaseCombatCamera").GetComponent<CinemachineCamera>();
|
||
|
|
||
|
BaseCombatCamera.Priority = 1;
|
||
|
|
||
|
MainCamera = Camera.main;
|
||
|
|
||
|
_vignette = GetEffect<Vignette>();
|
||
|
_vignette.active = false;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
// Methods
|
||
|
#region Methods
|
||
|
|
||
|
public void SetFollow(Transform target)
|
||
|
{
|
||
|
BaseCombatCamera.Follow = target;
|
||
|
}
|
||
|
|
||
|
// public void SetFollowAndLookAt(Transform target)
|
||
|
// {
|
||
|
// BaseCombatCamera.Follow = target;
|
||
|
// BaseCombatCamera.LookAt = target;
|
||
|
// }
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
// PostProcessing
|
||
|
#region PostProcessing
|
||
|
|
||
|
public void ToggleEffect<T>(bool value) where T : VolumeComponent
|
||
|
{
|
||
|
var effect = GetEffect<T>();
|
||
|
if (effect == null)
|
||
|
{
|
||
|
print(typeof(T) + "효과가 없습니다.");
|
||
|
return;
|
||
|
}
|
||
|
effect.active = value;
|
||
|
}
|
||
|
|
||
|
private T GetEffect<T>() where T : VolumeComponent
|
||
|
{
|
||
|
var postProcessVolume = FindAnyObjectByType<Volume>();
|
||
|
if (postProcessVolume == null)
|
||
|
{
|
||
|
print("Volume 컴포넌트를 가진 오브젝트가 없습니다.");
|
||
|
return null;
|
||
|
}
|
||
|
postProcessVolume.profile.TryGet(out T effect);
|
||
|
return effect;
|
||
|
}
|
||
|
|
||
|
public void LowHpVignette()
|
||
|
{
|
||
|
_lowHpVignetteCoroutine ??= StartCoroutine(LowHpVignetteCoroutine());
|
||
|
}
|
||
|
|
||
|
public void DefaultHpVignette()
|
||
|
{
|
||
|
Utils.EndUniqueCoroutine(this, ref _lowHpVignetteCoroutine);
|
||
|
_vignette.active = false;
|
||
|
}
|
||
|
|
||
|
private IEnumerator LowHpVignetteCoroutine()
|
||
|
{
|
||
|
var startValue = 0.2f;
|
||
|
var endValue = 0.3f;
|
||
|
var time = 0f;
|
||
|
|
||
|
_vignette.intensity.value = startValue;
|
||
|
_vignette.active = true;
|
||
|
|
||
|
while (true)
|
||
|
{
|
||
|
time += Time.deltaTime * 2f;
|
||
|
_vignette.intensity.value = Mathf.Lerp(startValue, endValue, time);
|
||
|
if (time >= 1f)
|
||
|
{
|
||
|
(startValue, endValue) = (endValue, startValue);
|
||
|
time = 0f;
|
||
|
}
|
||
|
yield return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|