using System;
using UnityEngine;

public class UI_ScreenCover : UI_ScreenFitBase
{
	protected override void Start()
	{
		this.m_MaskPanel = base.GetComponent<UIPanel>();
		this.m_CoverUI = base.GetComponent<UIWidget>();
		base.Start();
	}

	protected override void Update()
	{
		base.Update();
	}

	protected override void FitAction()
	{
		Vector3 point = new Vector3((float)Screen.width, (float)Screen.height);
		Vector3 vector = UI_ScreenFitBase.PointToScreenPos(point);
		if (!this.m_IsMasking && this.m_CoverUI)
		{
			UI_ScreenCover.CoverType myType = this.m_MyType;
			if (myType != UI_ScreenCover.CoverType.Horizontal)
			{
				if (myType != UI_ScreenCover.CoverType.Vertical)
				{
					if (this.m_UseSceenAsspect)
					{
						this.m_CoverUI.width = (int)(vector.x * 2f * this.m_ScreenRateX);
						this.m_CoverUI.height = (int)(vector.y * 2f * this.m_ScreenRateY);
					}
					else
					{
						this.m_CoverUI.width = (int)vector.x * 2;
						this.m_CoverUI.height = (int)vector.y * 2;
					}
				}
				else
				{
					this.m_CoverUI.height = (int)vector.y * 2;
					if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
					{
						this.m_CoverUI.width = (int)((float)this.m_CoverUI.height * (this.m_AsspectRatio.x / this.m_AsspectRatio.y));
					}
				}
			}
			else
			{
				this.m_CoverUI.width = (int)vector.x * 2;
				if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
				{
					this.m_CoverUI.height = (int)((float)this.m_CoverUI.width * (this.m_AsspectRatio.y / this.m_AsspectRatio.x));
				}
			}
			if (this.m_WidthMax > 0)
			{
				this.m_CoverUI.width = Mathf.Min(this.m_CoverUI.width, this.m_WidthMax);
			}
			if (this.m_HeightMax > 0)
			{
				this.m_CoverUI.height = Mathf.Min(this.m_CoverUI.height, this.m_HeightMax);
			}
		}
		else if (this.m_IsMasking && this.m_MaskPanel)
		{
			Vector4 zero = Vector4.zero;
			UI_ScreenCover.CoverType myType2 = this.m_MyType;
			if (myType2 != UI_ScreenCover.CoverType.Horizontal)
			{
				if (myType2 != UI_ScreenCover.CoverType.Vertical)
				{
					if (this.m_UseSceenAsspect)
					{
						zero.z = (float)((int)(vector.x * 2f * this.m_ScreenRateX));
						zero.w = (float)((int)(vector.y * 2f * this.m_ScreenRateY));
					}
					else
					{
						zero.z = (float)((int)vector.x * 2);
						zero.w = (float)((int)vector.y * 2);
					}
				}
				else
				{
					zero.w = (float)((int)vector.y * 2);
					if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
					{
						zero.z = (float)((int)((float)this.m_MaskPanel.clipTexture.height * (this.m_AsspectRatio.x / this.m_AsspectRatio.y)));
					}
				}
			}
			else
			{
				zero.z = (float)((int)vector.x * 2);
				if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
				{
					zero.w = (float)((int)((float)this.m_MaskPanel.clipTexture.width * (this.m_AsspectRatio.y / this.m_AsspectRatio.x)));
				}
			}
			if (this.m_WidthMax > 0)
			{
				zero.z = Mathf.Min(zero.z, (float)this.m_WidthMax);
			}
			if (this.m_HeightMax > 0)
			{
				zero.w = Mathf.Min(zero.w, (float)this.m_HeightMax);
			}
			this.m_MaskPanel.baseClipRegion = zero;
		}
	}

	private UIPanel m_MaskPanel;

	private UIWidget m_CoverUI;

	[SerializeField]
	private UI_ScreenCover.CoverType m_MyType;

	[SerializeField]
	[Header("解像度に合わせたマスキングを行うか")]
	private bool m_IsMasking;

	[SerializeField]
	[Header("Horizontal・Vertical時の画像の比率((0, 0)で比率固定されない)")]
	private Vector2 m_AsspectRatio = Vector2.zero;

	[SerializeField]
	[Header("解像度に対する割合で比率を固定する")]
	private bool m_UseSceenAsspect;

	[SerializeField]
	[Range(0f, 1f)]
	private float m_ScreenRateX = 1f;

	[SerializeField]
	[Range(0f, 1f)]
	private float m_ScreenRateY = 1f;

	[SerializeField]
	[Header("最大サイズ(-1で無効)")]
	private int m_WidthMax = -1;

	[SerializeField]
	private int m_HeightMax = -1;

	private enum CoverType
	{
		All,
		Horizontal,
		Vertical
	}
}
