hellbound/Assets/Scripts/Managers/Camera/CameraManager.cs

59 lines
2.1 KiB
C#
Raw Permalink Normal View History

2021-11-26 11:16:25 +03:00
using System;
using Cinemachine;
using UnityEngine;
public static class CameraManager
{
public static event Action OnCameraChanged;
public static event Action OnCameraBlendEnded;
private static CameraController _controller;
public static Camera Main => _controller.Main;
public static CameraFeedbacks Feedbacks { get; private set; }
private const bool DEFAULT_CAMERA_INSTANT_TARGET_SET = false;
public static void Init()
{
LoadController();
LoadFeedbacks();
}
private static void LoadController()
{
if(_controller == null)
_controller = Assets.CreateImmortal<CameraController>("Main/CameraController");
_controller.OnCameraChanged -= InvokeCameraChanged;
_controller.OnCameraBlendEnded -= InvokeCameraBlendEnded;
_controller.OnCameraChanged += InvokeCameraChanged;
_controller.OnCameraBlendEnded += InvokeCameraBlendEnded;
}
private static void InvokeCameraChanged() => OnCameraChanged?.Invoke();
private static void InvokeCameraBlendEnded() => OnCameraBlendEnded?.Invoke();
private static void LoadFeedbacks()
{
Feedbacks = _controller.GetComponentInChildren<CameraFeedbacks>();
if (Feedbacks == null)
throw new NullReferenceException("Camera feedbacks is null");
}
public static void Activate(CameraTypeEnum type) => _controller.SetActive(type);
public static void SetTarget(Transform target, bool instant = DEFAULT_CAMERA_INSTANT_TARGET_SET) =>
_controller.SetTarget(target, instant);
public static void SetTarget(Transform[] targetsTransforms, bool instant = DEFAULT_CAMERA_INSTANT_TARGET_SET, CameraGroupTargetParameters[] parameters = null) =>
_controller.SetTarget(targetsTransforms, parameters, instant);
public static Transform GetTarget() => _controller.TargetFollower.GetTarget();
public static CinemachineTargetGroup GetTargetGroup() =>
GetTarget().TryGetComponent(out CinemachineTargetGroup targetGroup) ? targetGroup : null;
public static CameraItem GetActiveCamera() => _controller.ActiveCamera;
}