using UnityEngine;

[ExecuteInEditMode]
public class AspectCamera : MonoBehaviour
{
	public Vector2 aspect = new Vector2(4f, 3f);

	public Color32 backgroundColor = Color.black;

	private float aspectRate;

	private Camera _camera;

	private static Camera _backgroundCamera;

	private int sizeVal = 1;

	public const float LOWER_LIMIT_ASPECT_RATIO = 0.5625f;

	public const float UPPER_LIMIT_ASPECT_RATIO = 0.4618f;

	public const float LOWER_LIMIT_ASPECT_RATIO_RECIPROCAL = 1.7777778f;

	private const float SAFE_AREA_RATE = 0.892f;

	private const float SAFE_AREA_NONE_RATE = 1f;

	public static float SafeAreaRate;

	private void Start()
	{
		aspectRate = aspect.x / aspect.y;
		_camera = GetComponent<Camera>();
		SafeAreaRate = 1f;
		float num = (float)Screen.height / (float)Screen.width;
		if (num < 0.5625f)
		{
			num = Mathf.Max(num, 0.4618f);
			float t = (0.5625f - num) / 0.10069999f;
			SafeAreaRate = Mathf.Lerp(1f, 0.892f, t);
		}
	}

	private void UpdateScreenRate()
	{
		float num = aspect.y / aspect.x;
		float num2 = (float)Screen.height / (float)Screen.width;
		if (num2 < 0.5625f)
		{
			num2 = 0.5625f;
		}
		if (num > num2)
		{
			float num3 = num2 / num;
			_camera.rect = new Rect(0f, 0f, 1f, 1f);
			_camera.orthographicSize = (float)sizeVal * num3;
		}
		else
		{
			float num4 = num / num2;
			_camera.rect = new Rect(0f, 0f, 1f, 1f);
			_camera.orthographicSize = (float)sizeVal / num4;
		}
	}

	private bool IsChangeAspect()
	{
		return _camera.aspect == aspectRate;
	}

	private void Update()
	{
		UpdateScreenRate();
		_camera.ResetAspect();
	}
}
