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

42 lines
1.1 KiB
C#
Raw Normal View History

2021-12-29 20:50:11 +03:00
using UnityEngine;
namespace RND
{
public class CamerasResolutionCorrector : MonoBehaviour
{
[SerializeField] private Vector2 _defaultResolution = new Vector2(360f, 640f);
[Range(0f, 1f)] public float _widthOrHeight = 0;
[SerializeField] private bool _debug;
private BaseCameraCorrector[] _correctors;
private void Awake()
{
Camera camera = GetComponent<Camera>();
_correctors = transform.parent.GetComponentsInChildren<BaseCameraCorrector>(true);
foreach (BaseCameraCorrector corrector in _correctors)
corrector.Init(camera, _defaultResolution);
}
private void OnEnable()
{
SyncFieldOfView();
}
private void Update()
{
if (_debug == false)
return;
SyncFieldOfView();
}
private void SyncFieldOfView()
{
foreach (BaseCameraCorrector data in _correctors)
data.SyncCameraProperty(_widthOrHeight);
}
}
}