69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using System;
|
|
using Cinemachine;
|
|
using UnityEngine;
|
|
|
|
namespace RND
|
|
{
|
|
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,
|
|
NullableVector3 overwrites = null)
|
|
=> _controller.SetTarget(target, instant, overwrites);
|
|
|
|
public static void SetTarget(
|
|
Transform[] targetsTransforms,
|
|
bool instant = DEFAULT_CAMERA_INSTANT_TARGET_SET,
|
|
CameraGroupTargetParameters[] parameters = null,
|
|
NullableVector3 overwrites = null)
|
|
=> _controller.SetTarget(targetsTransforms, parameters, instant, overwrites);
|
|
|
|
public static Transform GetTarget() => _controller.TargetFollower.GetTarget();
|
|
|
|
public static CinemachineTargetGroup GetTargetGroup() =>
|
|
GetTarget().TryGetComponent(out CinemachineTargetGroup targetGroup) ? targetGroup : null;
|
|
|
|
public static CameraItem GetActiveCamera() => _controller.ActiveCamera;
|
|
}
|
|
}
|