备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Cinemachine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShootingRangeCameraAspectAdjustment : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private CinemachineVirtualCamera virtualCamera;
|
||||
[SerializeField] private float aspectUpperLimit = 2.2f;
|
||||
private void Start()
|
||||
{
|
||||
if (virtualCamera == null)
|
||||
{
|
||||
Debug.LogError("No Virtual Camera found.", this);
|
||||
return;
|
||||
}
|
||||
float aspect = (float)Screen.height / Screen.width;
|
||||
// Debug.Log($"[FOV]height: {Screen.height}, width: {Screen.width}, aspect: {aspect}]");
|
||||
var oldFov = virtualCamera.m_Lens.FieldOfView;
|
||||
// Debug.Log($"[FOV]old fov: {oldFov}");
|
||||
if (aspect >= 16.0 / 9)
|
||||
{
|
||||
var newFov = 2 * math.atan(math.tan(oldFov * 0.5f / 180 * math.PI) * 9 / 16 * (aspect < aspectUpperLimit ? aspect : aspectUpperLimit)) / math.PI * 180;
|
||||
// Debug.Log($"[FOV]new fov raw{newFov}");
|
||||
// while (newFov < 0)
|
||||
// newFov += 180;
|
||||
// Debug.Log($"[FOV]new fov{newFov}");
|
||||
virtualCamera.m_Lens.FieldOfView = newFov;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user