36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using Cinemachine;
|
|
namespace BITKit
|
|
{
|
|
[Serializable]
|
|
public class CinemachineBasedAds:IProvider
|
|
{
|
|
public T Get<T>()
|
|
{
|
|
return CinemachineHelper.Singleton.Ads is T t? t : default;
|
|
}
|
|
}
|
|
public class CinemachineHelper : MonoBehaviour
|
|
{
|
|
internal static CinemachineHelper Singleton { get; private set; }
|
|
[SerializeReference, SubclassSelector] public References ads;
|
|
public float Ads { get; private set; }
|
|
public CinemachineBrain brain;
|
|
private void Awake()
|
|
{
|
|
Singleton = this;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
var playerConfig = Data.Get<PlayerConfig>();
|
|
var currentActive = brain.ActiveVirtualCamera as CinemachineVirtualCamera;
|
|
if (currentActive is not null && playerConfig is not null)
|
|
{
|
|
var currentFov = currentActive.m_Lens.FieldOfView;
|
|
Ads = currentFov / playerConfig.Fov;
|
|
}
|
|
}
|
|
}
|
|
} |