2024-08-14 10:52:35 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2024-06-06 11:07:07 +00:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using Unity.Cinemachine;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
2024-08-14 10:52:35 +00:00
|
|
|
public enum TycoonCameraType
|
|
|
|
{
|
|
|
|
Base = 0,
|
2024-09-24 10:35:49 +00:00
|
|
|
Storage
|
2024-08-14 10:52:35 +00:00
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public Camera UiCamera { get; private set; }
|
|
|
|
|
2024-09-26 11:50:39 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public Camera LiquidOverlayCamera { get; private set; }
|
|
|
|
|
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]
|
2024-09-24 10:35:49 +00:00
|
|
|
public CinemachineCamera StorageCamera { get; private set; }
|
2024-09-26 11:50:39 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Vector3 _transparencySortAxis;
|
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
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Unity events
|
|
|
|
#region Unity events
|
2024-10-14 11:13:08 +00:00
|
|
|
|
|
|
|
private void OnValidate()
|
|
|
|
{
|
|
|
|
SetTransparencySortAxis();
|
|
|
|
}
|
|
|
|
|
2024-06-06 11:07:07 +00:00
|
|
|
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-10-06 23:41:09 +00:00
|
|
|
UiCamera = MainCamera.transform.Find("UiCamera").GetComponent<Camera>();
|
|
|
|
LiquidOverlayCamera = GameObject.Find("LiquidOverlayCamera").GetComponent<Camera>();
|
2024-08-14 10:52:35 +00:00
|
|
|
_cinemachineBrain = GetComponent<CinemachineBrain>();
|
2024-06-06 11:07:07 +00:00
|
|
|
|
2024-08-14 10:52:35 +00:00
|
|
|
BaseCamera = cameraLocation.Find("BaseCamera").GetComponent<CinemachineCamera>();
|
2024-09-24 10:35:49 +00:00
|
|
|
StorageCamera = cameraLocation.Find("StorageCamera").GetComponent<CinemachineCamera>();
|
2024-08-14 10:52:35 +00:00
|
|
|
|
|
|
|
_cinemachineCameras.Add(BaseCamera);
|
2024-09-24 10:35:49 +00:00
|
|
|
_cinemachineCameras.Add(StorageCamera);
|
2024-08-14 10:52:35 +00:00
|
|
|
|
|
|
|
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-09-23 10:18:47 +00:00
|
|
|
public void SetMainCamera(TycoonCameraType tycoonCameraType)
|
2024-08-14 10:52:35 +00:00
|
|
|
{
|
|
|
|
var newMainCamera = tycoonCameraType switch
|
|
|
|
{
|
|
|
|
TycoonCameraType.Base => BaseCamera,
|
2024-09-24 10:35:49 +00:00
|
|
|
TycoonCameraType.Storage => StorageCamera,
|
2024-08-14 10:52:35 +00:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(tycoonCameraType), tycoonCameraType, null)
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach (var element in _cinemachineCameras)
|
|
|
|
{
|
|
|
|
element.Priority = 0;
|
|
|
|
}
|
|
|
|
|
2024-09-23 10:18:47 +00:00
|
|
|
//_cinemachineBrain.DefaultBlend.Style = styles;
|
2024-08-14 10:52:35 +00:00
|
|
|
newMainCamera.Priority = 1;
|
2024-09-26 11:50:39 +00:00
|
|
|
SetTransparencySortAxis();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetTransparencySortAxis()
|
|
|
|
{
|
|
|
|
var camera = Camera.main;
|
|
|
|
camera.transparencySortMode = TransparencySortMode.CustomAxis;
|
|
|
|
camera.transparencySortAxis = _transparencySortAxis;
|
2024-08-14 10:52:35 +00:00
|
|
|
}
|
2024-10-22 12:41:31 +00:00
|
|
|
|
|
|
|
[Button("테스트용")]
|
|
|
|
private void Test()
|
|
|
|
{
|
|
|
|
var camera = Camera.main;
|
|
|
|
camera.transparencySortMode = TransparencySortMode.CustomAxis;
|
|
|
|
camera.transparencySortAxis = new Vector3(0, Mathf.Sin(Mathf.Deg2Rad * 40), Mathf.Cos(Mathf.Deg2Rad * 40));
|
|
|
|
}
|
2024-06-06 11:07:07 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|