SamsonGame/Assets/Scripts/Game/Camera/CameraDistanceCorrector.cs

29 lines
831 B
C#
Raw Permalink Normal View History

2021-12-29 20:50:11 +03:00
using System;
using Cinemachine;
using UnityEngine;
namespace RND
{
public class CameraDistanceCorrector : BaseCameraCorrector
{
private CinemachineFramingTransposer _framingTransposer;
private float _defaultDistance;
private float _coefficient;
protected override void OnInit()
{
_framingTransposer = VirtualCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
if (_framingTransposer == null)
return;
_defaultDistance = _framingTransposer.m_CameraDistance;
}
public override void SyncCameraProperty(float widthOrHeight)
{
_coefficient = DefaultRatio / Camera.aspect;
_framingTransposer.m_CameraDistance = _defaultDistance * _coefficient;
}
}
}