2024-08-14 10:52:35 +00:00
|
|
|
using System;
|
2024-06-06 11:07:07 +00:00
|
|
|
using System.Collections;
|
2024-08-14 10:52:35 +00:00
|
|
|
using System.Collections.Generic;
|
2024-06-06 11:07:07 +00:00
|
|
|
using BlueWater.Utility;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using Unity.Cinemachine;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
using UnityEngine.Rendering.Universal;
|
2024-08-14 10:52:35 +00:00
|
|
|
using UnityEngine.Serialization;
|
2024-06-06 11:07:07 +00:00
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
2024-08-14 10:52:35 +00:00
|
|
|
public enum TycoonCameraType
|
|
|
|
{
|
|
|
|
Base = 0,
|
|
|
|
Bar
|
|
|
|
}
|
|
|
|
|
2024-06-06 11:07:07 +00:00
|
|
|
public class TycoonCameraManager : Singleton<TycoonCameraManager>
|
|
|
|
{
|
|
|
|
// Components
|
|
|
|
#region Components
|
|
|
|
|
|
|
|
[Title("카메라")]
|
2024-08-14 10:52:35 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public Camera MainCamera { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Camera UiCamera { get; private set; }
|
|
|
|
|
|
|
|
[FormerlySerializedAs("_cinemachineCameras")]
|
2024-06-06 11:07:07 +00:00
|
|
|
[SerializeField]
|
2024-08-14 10:52:35 +00:00
|
|
|
private Transform cameraLocation;
|
2024-06-06 11:07:07 +00:00
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public CinemachineCamera BaseCamera { get; private set; }
|
2024-08-14 10:52:35 +00:00
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public CinemachineCamera BarCamera { get; private set; }
|
2024-06-06 11:07:07 +00:00
|
|
|
|
|
|
|
// Variables
|
2024-08-14 10:52:35 +00:00
|
|
|
private CinemachineBrain _cinemachineBrain;
|
|
|
|
private List<CinemachineCamera> _cinemachineCameras = new();
|
|
|
|
|
2024-06-06 11:07:07 +00:00
|
|
|
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.OnInstantiatePlayer += SetFollow;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
if (!GameManager.Instance) return;
|
|
|
|
|
|
|
|
GameManager.Instance.OnInstantiatePlayer -= SetFollow;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Initialize methods
|
|
|
|
#region Initialize methods
|
|
|
|
|
|
|
|
[Button("셋팅 초기화")]
|
|
|
|
private void Initialize()
|
|
|
|
{
|
2024-08-14 10:52:35 +00:00
|
|
|
cameraLocation = GameObject.Find("CinemachineCameras").transform;
|
2024-06-06 11:07:07 +00:00
|
|
|
|
2024-07-02 18:27:56 +00:00
|
|
|
MainCamera = GetComponent<Camera>();
|
2024-08-14 10:52:35 +00:00
|
|
|
_cinemachineBrain = GetComponent<CinemachineBrain>();
|
2024-08-22 10:39:15 +00:00
|
|
|
//UiCamera = MainCamera.transform.Find("UiCamera").GetComponent<Camera>();
|
2024-06-06 11:07:07 +00:00
|
|
|
|
2024-08-14 10:52:35 +00:00
|
|
|
BaseCamera = cameraLocation.Find("BaseCamera").GetComponent<CinemachineCamera>();
|
|
|
|
BarCamera = cameraLocation.Find("BarCamera").GetComponent<CinemachineCamera>();
|
|
|
|
|
2024-06-06 11:07:07 +00:00
|
|
|
_vignette = GetEffect<Vignette>();
|
|
|
|
_vignette.active = false;
|
2024-08-14 10:52:35 +00:00
|
|
|
|
|
|
|
_cinemachineCameras.Add(BaseCamera);
|
|
|
|
_cinemachineCameras.Add(BarCamera);
|
|
|
|
|
|
|
|
SetMainCamera(TycoonCameraType.Base);
|
2024-06-06 11:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
public void SetFollow(Transform target)
|
|
|
|
{
|
|
|
|
BaseCamera.Follow = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
// public void SetFollowAndLookAt(Transform target)
|
|
|
|
// {
|
|
|
|
// BaseCombatCamera.Follow = target;
|
|
|
|
// BaseCombatCamera.LookAt = target;
|
|
|
|
// }
|
|
|
|
|
2024-08-14 10:52:35 +00:00
|
|
|
public void SetMainCamera(TycoonCameraType tycoonCameraType, CinemachineBlendDefinition.Styles styles = CinemachineBlendDefinition.Styles.Cut)
|
|
|
|
{
|
|
|
|
var newMainCamera = tycoonCameraType switch
|
|
|
|
{
|
|
|
|
TycoonCameraType.Base => BaseCamera,
|
|
|
|
TycoonCameraType.Bar => BarCamera,
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(tycoonCameraType), tycoonCameraType, null)
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach (var element in _cinemachineCameras)
|
|
|
|
{
|
|
|
|
element.Priority = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cinemachineBrain.DefaultBlend.Style = styles;
|
|
|
|
newMainCamera.Priority = 1;
|
|
|
|
}
|
|
|
|
|
2024-06-06 11:07:07 +00:00
|
|
|
#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
|
|
|
|
}
|
|
|
|
}
|