using System;
using System.Reflection;
using UnityEngine;

[RequireComponent(typeof(Camera))]
[ExecuteInEditMode]
public class AMCameraFade : MonoBehaviour
{
	public static Texture2D blankTexture
	{
		get
		{
			if (!AMCameraFade._blankTexture)
			{
				AMCameraFade._blankTexture = AMCameraFade.getBlankTexture();
			}
			return AMCameraFade._blankTexture;
		}
	}

	public static Material matIris
	{
		get
		{
			if (AMCameraFade._matIris == null)
			{
				AMCameraFade._matIris = AMCameraFade.getMaterialIris();
			}
			return AMCameraFade._matIris;
		}
	}

	[HideInInspector]
	private RenderTexture tex
	{
		get
		{
			return this.getRenderTexture();
		}
	}

	private void Awake()
	{
		if (Application.isPlaying && this.preview)
		{
			this.destroy();
		}
		else
		{
			Camera component = base.GetComponent<Camera>();
			component.clearFlags = CameraClearFlags.Nothing;
			component.cullingMask = 0;
			component.depth = -1f;
			this.keepAliveAwake = true;
		}
	}

	private void OnGUI()
	{
		if (this.isReset || (!this.hasColorTex && ((!this.useRenderTexture && !this.tex2d) || (this.useRenderTexture && !this.renderTextureCamera))))
		{
			return;
		}
		GUI.depth = -9999999;
		if (this.hasColorBG)
		{
			GUI.color = new Color(this.colorBG.r, this.colorBG.g, this.colorBG.b, 1f);
			GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), AMCameraFade.blankTexture);
		}
		if (this.hasColorTex)
		{
			GUI.color = new Color(this.colorTex.r, this.colorTex.g, this.colorTex.b, 1f);
		}
		else
		{
			GUI.color = Color.white;
		}
		AMCameraFade.processCameraFade(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (!this.hasColorTex) ? ((!this.useRenderTexture) ? this.tex2d : this.tex) : AMCameraFade.blankTexture, this.mode, this.value, this.percent, this.r, this.irisShape, Event.current);
		if (!Application.isPlaying)
		{
			float num = 0f;
			bool flag = false;
			if ((float)this.height > 0f)
			{
				num = (float)this.width / (float)this.height;
			}
			else
			{
				flag = true;
			}
			this.width = Screen.width;
			this.height = Screen.height;
			float num2 = (float)this.width / (float)this.height;
			if (flag || (num > 0f && num2.ToString("N1") != num.ToString("N1")))
			{
				this.doForceUpdate(false);
			}
			if (!this.isReset && this.placeholder)
			{
				GUI.color = Color.black;
				GUI.DrawTexture(new Rect(0f, (float)Screen.height - 25f, (float)Screen.width, 25f), this.tex);
				GUI.color = Color.white;
				GUI.Label(new Rect(5f, (float)Screen.height - 20f - 2f, (float)Screen.width - 10f, 20f), "This is a placeholder. Transitions can only be previewed with a Unity Pro license.");
			}
		}
	}

	private void Update()
	{
		if (this.deleteMe)
		{
			Debug.Log("Animator: Deleted AMCameraFade" + ((!this.preview) ? string.Empty : "Preview"));
		}
		if (!Application.isPlaying)
		{
			if (this.deleteMe)
			{
				this.destroyImmediate();
			}
			else if (this.updateTexture)
			{
				this.doForceUpdate(true);
			}
			return;
		}
		if (this.preview || this.deleteMe || (!this.keepAliveAwake && !this.keepAliveColor && this.keepAlives <= 0 && !this.keepAlivePreview))
		{
			this.destroy();
		}
	}

	private void doForceUpdate(bool showMsg = false)
	{
		if (this.useRenderTexture)
		{
			this.shouldUpdateRenderTexture = true;
		}
		else
		{
			AMCameraFade.doShouldUpdateStill();
		}
		this.updateTexture = false;
		if (showMsg)
		{
			Debug.Log("Animator: Updated AMCameraFade" + ((!this.preview) ? string.Empty : "Preview") + " Texture");
		}
	}

	public void destroyImmediate()
	{
		AMTween.Stop(base.gameObject);
		if (this._tex)
		{
			if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this._tex)
			{
				this.renderTextureCamera.targetTexture = null;
			}
			UnityEngine.Object.DestroyImmediate(this._tex);
		}
		AMCameraFade._cf = null;
		UnityEngine.Object.DestroyImmediate(base.gameObject);
	}

	public void destroy()
	{
		AMTween.Stop(base.gameObject);
		if (this._tex)
		{
			if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this._tex)
			{
				this.renderTextureCamera.targetTexture = null;
			}
			UnityEngine.Object.Destroy(this._tex);
		}
		AMCameraFade._cf = null;
		UnityEngine.Object.Destroy(base.gameObject);
	}

	public static void processCameraFade(Rect rect, Texture tex, int mode, float value, float percent, float[] r, Texture2D _irisShape, Event editorEvent)
	{
		if (_irisShape != null && AMCameraFade.matIris.GetTexture("_Mask") != _irisShape)
		{
			AMCameraFade.matIris.SetTexture("_Mask", _irisShape);
		}
		switch (mode)
		{
		case 1:
			if (((r.Length < 1) ? 0f : r[0]) == 0f)
			{
				AMCameraFade.processVenetianBlindsVertical(rect, tex, value, (r.Length < 2) ? 5 : ((int)r[1]));
			}
			else
			{
				AMCameraFade.processVenetianBlindsHorizontal(rect, tex, value, (int)r[1]);
			}
			return;
		case 2:
		{
			bool flag = ((r.Length < 2) ? 0f : r[1]) == 0f;
			float num = (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f);
			if (r.Length < 1 || r[0] == 0f)
			{
				if (flag)
				{
					AMCameraFade.processDoorsVerticalOpen(rect, tex, value, num);
				}
				else
				{
					AMCameraFade.processDoorsVerticalClose(rect, tex, value, num);
				}
			}
			else if (flag)
			{
				AMCameraFade.processDoorsHorizontalOpen(rect, tex, value, num);
			}
			else
			{
				AMCameraFade.processDoorsHorizontalClose(rect, tex, value, num);
			}
			return;
		}
		case 3:
			if (((r.Length < 1) ? 0f : r[0]) == 0f)
			{
				AMCameraFade.processIrisBoxShrink(rect, tex, value, (r.Length < 2) ? 0.5f : Mathf.Clamp(r[1], 0f, 1f), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f));
			}
			else
			{
				AMCameraFade.processIrisBoxGrow(rect, tex, value, (r.Length < 2) ? 0.5f : Mathf.Clamp(r[1], 0f, 1f), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f));
			}
			return;
		case 4:
			AMCameraFade.processIrisRound(rect, tex, ((r.Length < 1) ? 0f : r[0]) == 0f, value, (r.Length < 2) ? 2.5f : r[1], (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f), (r.Length < 4) ? 0.5f : Mathf.Clamp(r[3], 0f, 1f), _irisShape, editorEvent);
			return;
		case 6:
			AMCameraFade.processIrisShape(rect, tex, ((r.Length < 1) ? 0f : r[0]) == 0f, value, percent, (r.Length < 5) ? 0.5f : Mathf.Clamp(r[4], 0f, 1f), (r.Length < 6) ? 0.5f : Mathf.Clamp(r[5], 0f, 1f), _irisShape, (r.Length < 2 || r[1] <= 0f) ? 6f : r[1], (r.Length < 7) ? 0.5f : r[6], (r.Length < 8) ? 0.5f : r[7], (r.Length < 3) ? 50 : ((int)r[2]), ((r.Length < 4) ? 0f : r[3]) == 1f, editorEvent);
			return;
		case 7:
			AMCameraFade.processShapeWipe(rect, tex, value, _irisShape, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 6f : r[1], (r.Length < 3) ? 0f : r[2], (r.Length < 4) ? 3f : r[3], (r.Length < 5) ? -3f : r[4], editorEvent);
			return;
		case 8:
			AMCameraFade.processLinearWipe(rect, tex, value, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 0.25f : r[1], _irisShape, editorEvent);
			return;
		case 9:
			AMCameraFade.processRadialWipe(rect, tex, value, ((r.Length < 1) ? 0f : r[0]) == 0f, (r.Length < 2) ? 0 : ((int)r[1]), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f), (r.Length < 4) ? 0.5f : Mathf.Clamp(r[3], 0f, 1f), editorEvent);
			return;
		case 10:
			AMCameraFade.processWedgeWipe(rect, tex, value, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 0.5f : Mathf.Clamp(r[1], 0f, 1f), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f), editorEvent);
			return;
		}
		AMCameraFade.processAlpha(rect, tex, value);
	}

	public void setupMaterials()
	{
		switch (this.mode)
		{
		case 4:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
			AMCameraFade.matIris.SetMatrix("_MatrixTex", Matrix4x4.zero);
			AMCameraFade.matIris.SetTexture("_Mask", this.irisShape);
			break;
		}
	}

	public static bool needsTexture(int mode)
	{
		switch (mode)
		{
		case 4:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
			return true;
		}
		return false;
	}

	public static void processAlpha(Rect rect, Texture tex, float value)
	{
		GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, value);
		GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex);
	}

	public static void processDoorsVerticalOpen(Rect rect, Texture tex, float value, float focalX)
	{
		float num = rect.width * focalX * value;
		float num2 = (rect.width - rect.width * focalX) * value;
		float num3 = 0f;
		float num4 = rect.width - num2;
		float num5 = focalX * value;
		float num6 = (1f - focalX) * value;
		float x = 0f;
		float x2 = 1f - num6;
		GUI.DrawTextureWithTexCoords(new Rect(rect.x + num3, rect.y, num, rect.height), tex, new Rect(x, 0f, num5, 1f));
		GUI.DrawTextureWithTexCoords(new Rect(rect.x + num4, rect.y, num2, rect.height), tex, new Rect(x2, 0f, num6, 1f));
	}

	public static void processDoorsVerticalClose(Rect rect, Texture tex, float value, float focalX)
	{
		float num = rect.width * focalX * value;
		float num2 = (rect.width - rect.width * focalX) * value;
		float num3 = rect.width * focalX - num;
		float num4 = rect.width * focalX;
		float num5 = focalX * value;
		float num6 = (1f - focalX) * value;
		float x = focalX - num5;
		GUI.DrawTextureWithTexCoords(new Rect(rect.x + num3, rect.y, num, rect.height), tex, new Rect(x, 0f, num5, 1f));
		GUI.DrawTextureWithTexCoords(new Rect(rect.x + num4, rect.y, num2, rect.height), tex, new Rect(focalX, 0f, num6, 1f));
	}

	public static void processDoorsHorizontalOpen(Rect rect, Texture tex, float value, float focalY)
	{
		float num = rect.height * focalY * value;
		float num2 = (rect.height - rect.height * focalY) * value;
		float num3 = 0f;
		float num4 = rect.height - num2;
		float num5 = focalY * value;
		float num6 = (1f - focalY) * value;
		float y = 1f - focalY * value;
		float y2 = 0f;
		GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num3, rect.width, num), tex, new Rect(0f, y, 1f, num5));
		GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num4, rect.width, num2), tex, new Rect(0f, y2, 1f, num6));
	}

	public static void processDoorsHorizontalClose(Rect rect, Texture tex, float value, float focalY)
	{
		float num = rect.height * focalY * value;
		float num2 = (rect.height - rect.height * focalY) * value;
		float num3 = rect.height * focalY - num;
		float num4 = rect.height * focalY;
		float num5 = focalY * value;
		float num6 = (1f - focalY) * value;
		float y = 1f - focalY;
		float y2 = 1f - focalY - num6;
		GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num3, rect.width, num), tex, new Rect(0f, y, 1f, num5));
		GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num4, rect.width, num2), tex, new Rect(0f, y2, 1f, num6));
	}

	public static void processVenetianBlindsVertical(Rect rect, Texture tex, float value, int resolution)
	{
		for (int i = 0; i < resolution; i++)
		{
			float num = rect.width / (float)resolution * (float)i + (1f - value) * (rect.width / (float)resolution) / 2f;
			float num2 = rect.width / (float)resolution * value;
			float x = 1f / (float)resolution * (float)i + (1f - value) * (1f / (float)resolution) / 2f;
			float num3 = 1f / (float)resolution * value;
			GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y, num2, rect.height), tex, new Rect(x, 0f, num3, 1f));
		}
	}

	public static void processVenetianBlindsHorizontal(Rect rect, Texture tex, float value, int resolution)
	{
		for (int i = 0; i < resolution; i++)
		{
			float num = rect.height - rect.height / (float)resolution * (float)(i + 1) + (1f - value) * (rect.height / (float)resolution) / 2f;
			float num2 = rect.height / (float)resolution * value;
			float y = 1f / (float)resolution * (float)i + (1f - value) * (1f / (float)resolution) / 2f;
			float num3 = 1f / (float)resolution * value;
			GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num, rect.width, num2), tex, new Rect(0f, y, 1f, num3));
		}
	}

	public static void processIrisBoxGrow(Rect rect, Texture tex, float value, float focalX, float focalY)
	{
		float num = rect.width * focalX * value;
		float num2 = rect.height * focalY * value;
		float num3 = rect.width * (1f - value);
		float num4 = rect.height * (1f - value);
		float x = focalX * value;
		float y = (1f - focalY) * value;
		float num5 = 1f - value;
		float num6 = 1f - value;
		GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y + num2, num3, num4), tex, new Rect(x, y, num5, num6));
	}

	public static void processIrisBoxShrink(Rect rect, Texture tex, float value, float focalX, float focalY)
	{
		float num = rect.width * focalX * (1f - value);
		float num2 = rect.height * focalY * (1f - value);
		float num3 = rect.width * value;
		float num4 = rect.height * value;
		float x = focalX * (1f - value);
		float y = (1f - focalY) * (1f - value);
		GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y + num2, num3, num4), tex, new Rect(x, y, value, value));
	}

	public static void processIrisRound(Rect rect, Texture tex, bool shrink, float value, float maxScale, float focalX, float focalY, Texture2D irisShape, Event editorEvent)
	{
		AMCameraFade.processIrisShape(rect, tex, shrink, value, 1f, focalX, focalY, irisShape, maxScale, 0.5f, 0.5f, 0, true, editorEvent);
	}

	public static void processIrisShape(Rect rect, Texture tex, bool shrink, float value, float percent, float focalX, float focalY, Texture shape, float maxScale, float pivotX, float pivotY, int rotateAmount, bool easeRotation, Event editorEvent)
	{
		if (editorEvent.type.Equals(EventType.Repaint))
		{
			focalY = 1f - focalY;
			float num = ((!shrink) ? (1f - value) : value) * maxScale;
			if (num <= 0.01f)
			{
				num = 0f;
			}
			if ((double)num <= 0.04)
			{
				AMCameraFade.matIris.SetFloat("_Cutoff", 0.8f);
			}
			else
			{
				AMCameraFade.matIris.SetFloat("_Cutoff", 0.1f);
			}
			float num2 = rect.width / rect.height;
			Vector2 vector = new Vector2(0f, 0f);
			vector.x = focalX - num / 2f / num2;
			vector.y = focalY - 0.5f * num;
			Vector3 s = new Vector3(1f / num * num2, 1f / num, 1f);
			Vector3 pos = new Vector3(-1f * vector.x * s.x, -1f * vector.y * s.y, 0f);
			float num3 = ((!shrink) ? 1f : 0f) - value;
			pivotY = 1f - pivotY;
			pivotX = pivotX / 2f + 0.25f;
			pivotY = pivotY / 2f + 0.25f;
			Vector2 vector2 = new Vector2(pivotX + (0.5f - pivotX) * num3, pivotY + (0.5f - pivotY) * num3);
			Matrix4x4 rhs = Matrix4x4.TRS(-vector2, Quaternion.identity, Vector3.one);
			float num4 = (float)rotateAmount * 5f;
			if (easeRotation)
			{
				num4 *= num3;
			}
			else
			{
				num4 *= percent;
			}
			Quaternion q = Quaternion.Euler(0f, 0f, num4);
			Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
			Matrix4x4 lhs = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one);
			Matrix4x4 rhs3 = Matrix4x4.TRS(pos, Quaternion.identity, s);
			AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
			AMCameraFade.matIris.color = GUI.color;
			Graphics.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex, AMCameraFade.matIris);
		}
	}

	public static void processLinearWipe(Rect rect, Texture tex, float value, int angle, float padding, Texture2D irisShape, Event editorEvent)
	{
		AMCameraFade.processShapeWipe(rect, tex, value, irisShape, angle, 1f, padding, 0f, 0f, editorEvent);
	}

	public static void processShapeWipe(Rect rect, Texture tex, float value, Texture shape, int angle, float scale, float padding, float offsetStart, float offsetEnd, Event editorEvent)
	{
		if (editorEvent.type.Equals(EventType.Repaint))
		{
			int num = angle + 90;
			float num2 = rect.width / rect.height;
			Vector3 s = new Vector3(1f / scale * num2, 1f / scale, 1f);
			Vector2 vector = AMCameraFade.getPositionAtAngle(num, padding);
			Vector2 a = AMCameraFade.getPositionAtAngle((num + 180) % 360, padding);
			Vector2 normalized = (a - vector).normalized;
			vector += -normalized * offsetEnd;
			a += -normalized * offsetStart;
			Vector2 vector2 = new Vector2(0.5f, 0.5f);
			Vector2 vector3 = new Vector2(a.x - vector.x, a.y - vector.y);
			Vector2 vector4 = new Vector2(0f, 0f);
			vector4.x = vector.x + vector3.x * value;
			vector4.y = vector.y + vector3.y * value;
			Vector2 v = new Vector3(-vector4.x * s.x + 0.5f, -vector4.y * s.y + 0.5f);
			Matrix4x4 rhs = Matrix4x4.TRS(-vector2, Quaternion.identity, Vector3.one);
			Quaternion q = Quaternion.Euler(0f, 0f, (float)(num - 90));
			Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
			Matrix4x4 lhs = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one);
			Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
			AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
			if (AMCameraFade.matIris.color != GUI.color)
			{
				AMCameraFade.matIris.color = GUI.color;
			}
			Graphics.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex, AMCameraFade.matIris);
		}
	}

	public static void processRadialWipe(Rect rect, Texture tex, float value, bool clockwise, int startingAngle, float focalX, float focalY, Event editorEvent)
	{
		if (value <= 0f)
		{
			return;
		}
		if (value >= 1f)
		{
			GUI.DrawTexture(rect, tex);
			return;
		}
		if (editorEvent.type.Equals(EventType.Repaint))
		{
			if (!clockwise)
			{
				startingAngle = (startingAngle + 180) % 360;
			}
			AMCameraFade.matIris.SetFloat("_Cutoff", 0f);
			float num = 1f;
			float num2 = (float)(startingAngle + 90) + 360f * (1f - value) * ((!clockwise) ? -1f : 1f);
			float num3 = rect.width / rect.height;
			Vector3 s = new Vector3(1f / num * num3, 1f / num, 1f);
			Vector2 vector = new Vector2(0.5f, 0.5f);
			Vector2 vector2 = new Vector2(focalX, 1f - focalY);
			Vector2 v = new Vector3(-vector2.x * s.x + 0.5f, -vector2.y * s.y + 0.5f);
			Matrix4x4 rhs = Matrix4x4.TRS(-vector, Quaternion.identity, Vector3.one);
			Quaternion q = Quaternion.Euler(0f, 0f, num2 - 90f);
			Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
			Matrix4x4 lhs = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one);
			Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
			AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
			if (AMCameraFade.matIris.color != GUI.color)
			{
				AMCameraFade.matIris.color = GUI.color;
			}
			Rect rect2 = new Rect(0f, 0f, 1f, 1f);
			Rect rect3 = new Rect(0f, 0f, 1f, 1f);
			Rect rect4 = new Rect(rect);
			bool flag = value > 0.5f;
			if ((float)startingAngle == 0f)
			{
				rect3.width = focalX;
				rect4.width = rect.width * focalX;
			}
			else if ((float)startingAngle == 90f)
			{
				rect3.y = 1f - focalY;
				rect3.height = focalY;
				rect4.height = rect.height * focalY;
			}
			else if ((float)startingAngle == 180f)
			{
				rect3.x = focalX;
				rect3.width = 1f - focalX;
				rect4.x = rect.x + rect.width * focalX;
				rect4.width = rect.width * (1f - focalX);
			}
			else if ((float)startingAngle == 270f)
			{
				rect3.height = 1f - focalY;
				rect4.y = rect.y + rect.height * focalY;
				rect4.height = rect.height * (1f - focalY);
			}
			Graphics.DrawTexture(flag ? rect : rect4, tex, flag ? rect2 : rect3, 0, 0, 0, 0, AMCameraFade.matIris);
			if (flag)
			{
				GUI.DrawTextureWithTexCoords(rect4, tex, rect3);
			}
		}
	}

	public static void processWedgeWipe(Rect rect, Texture tex, float value, int startingAngle, float focalX, float focalY, Event editorEvent)
	{
		if (value <= 0f)
		{
			return;
		}
		if (value >= 1f)
		{
			GUI.DrawTexture(rect, tex);
			return;
		}
		if (editorEvent.type.Equals(EventType.Repaint))
		{
			AMCameraFade.matIris.SetFloat("_Cutoff", 0f);
			float num = 1f;
			float num2 = (float)(startingAngle + 90) + 360f * (0.5f - value / 2f);
			float num3 = rect.width / rect.height;
			Vector3 s = new Vector3(1f / num * num3, 1f / num, 1f);
			Vector2 vector = new Vector2(0.5f, 0.5f);
			Vector2 vector2 = new Vector2(focalX, 1f - focalY);
			Vector2 v = new Vector3(-vector2.x * s.x + 0.5f, -vector2.y * s.y + 0.5f);
			Matrix4x4 rhs = Matrix4x4.TRS(-vector, Quaternion.identity, Vector3.one);
			Quaternion q = Quaternion.Euler(0f, 0f, num2 - 90f);
			Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
			Matrix4x4 lhs = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one);
			Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
			AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
			if (AMCameraFade.matIris.color != GUI.color)
			{
				AMCameraFade.matIris.color = GUI.color;
			}
			Rect sourceRect = new Rect(0f, 0f, 1f, 1f);
			Rect screenRect = new Rect(rect);
			Rect sourceRect2 = new Rect(0f, 0f, 1f, 1f);
			Rect screenRect2 = new Rect(rect);
			if ((float)startingAngle == 0f)
			{
				sourceRect.width = focalX;
				screenRect.width = rect.width * focalX;
				sourceRect2.x = focalX;
				sourceRect2.width = 1f - focalX;
				screenRect2.x = rect.x + rect.width * focalX;
				screenRect2.width = rect.width - screenRect.width;
			}
			else if ((float)startingAngle == 90f)
			{
				sourceRect.height = focalY;
				sourceRect.y = 1f - focalY;
				screenRect.height = rect.height * focalY;
				sourceRect2.height = 1f - sourceRect.height;
				screenRect2.y = rect.y + rect.height * focalY;
				screenRect2.height = rect.height - screenRect.height;
			}
			else if ((float)startingAngle == 180f)
			{
				sourceRect.x = focalX;
				sourceRect.width = 1f - focalX;
				screenRect.x = rect.x + rect.width * focalX;
				screenRect.width = rect.width * (1f - focalX);
				sourceRect2.width = focalX;
				screenRect2.width = rect.width * focalX;
			}
			else if ((float)startingAngle == 270f)
			{
				sourceRect.height = 1f - focalY;
				screenRect.y = rect.y + rect.height * focalY;
				screenRect.height = rect.height * (1f - focalY);
				sourceRect2.height = focalY;
				sourceRect2.y = 1f - focalY;
				screenRect2.height = rect.height * focalY;
			}
			Graphics.DrawTexture(screenRect2, tex, sourceRect2, 0, 0, 0, 0, AMCameraFade.matIris);
			startingAngle = (startingAngle + 180) % 360;
			num2 = (float)(startingAngle + 90) + 360f * (0.5f - value / 2f) * -1f;
			q = Quaternion.Euler(0f, 0f, num2 - 90f);
			rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
			AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
			Graphics.DrawTexture(screenRect, tex, sourceRect, 0, 0, 0, 0, AMCameraFade.matIris);
		}
	}

	private static Texture2D getBlankTexture()
	{
		Texture2D texture2D = (Texture2D)Resources.Load("am_blank_texture");
		if (!texture2D)
		{
			texture2D = new Texture2D(1, 1);
			texture2D.SetPixel(0, 0, Color.white);
			texture2D.Apply();
		}
		return texture2D;
	}

	private static Material getMaterialIris()
	{
		Material material = (Material)Resources.Load("AMIrisShapeMaterial");
		if (!material)
		{
			material = new Material("Shader \"Animator/AMIrisShape\" {Properties {\t_MainTex (\"Base (RGB)\", 2D) = \"white\" {}\t_Mask (\"Culling Mask\", 2D) = \"white\" {}\t_Cutoff (\"Alpha cutoff\", Range (0,1)) = 0.1  \t_Color (\"Main Color\", Color) = (1,1,1,1) }SubShader {\tTags {\"Queue\"=\"Background\"}\tLighting Off\tZWrite Off\tBlend SrcAlpha OneMinusSrcAlpha\tAlphaTest GEqual [_Cutoff]\tPass {\t\tSetTexture [_Mask] { matrix [_Matrix] combine texture }\t\tSetTexture [_MainTex] { ConstantColor [_Color] matrix[_TexMatrix] combine texture * constant, previous }\t}}}");
		}
		return material;
	}

	private static Material getMaterialRadial()
	{
		return (Material)Resources.Load("AMRadialWipeMaterial");
	}

	public static AMCameraFade getCameraFade(bool preview = false)
	{
		if (AMCameraFade._cf)
		{
			AMCameraFade._cf.preview = preview;
			return AMCameraFade._cf;
		}
		AMCameraFade amcameraFade = null;
		GameObject gameObject = GameObject.Find("AMCamera" + ((!preview) ? "Fade" : "FadePreview"));
		if (gameObject)
		{
			amcameraFade = (AMCameraFade)gameObject.GetComponent(typeof(AMCameraFade));
		}
		if (!amcameraFade)
		{
			amcameraFade = (AMCameraFade)new GameObject("AMCamera" + ((!preview) ? "Fade" : "FadePreview"), new Type[]
			{
				typeof(AMCameraFade)
			}).GetComponent(typeof(AMCameraFade));
		}
		AMCameraFade._cf = amcameraFade;
		AMCameraFade._cf.preview = preview;
		return AMCameraFade._cf;
	}

	public void setupRenderTexture(Camera camera)
	{
		if (this.renderTextureCamera != camera)
		{
			if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this.tex)
			{
				this.renderTextureCamera.targetTexture = null;
			}
			camera.targetTexture = this.tex;
			this.renderTextureCamera = camera;
			camera.Render();
		}
		this.useRenderTexture = true;
		this.colorTex = Color.white;
		this.hasColorTex = false;
		this.placeholder = false;
	}

	public bool isRenderTextureSetupFor(Camera camera)
	{
		return this.tex && camera.targetTexture == this.tex;
	}

	public static void reset()
	{
		if (AMCameraFade._cf != null)
		{
			AMCameraFade._cf.isReset = true;
			AMCameraFade._cf.value = 0f;
			if (AMCameraFade._cf.renderTextureCamera)
			{
				if (AMCameraFade._cf.renderTextureCamera.targetTexture == AMCameraFade._cf.tex)
				{
					AMCameraFade._cf.renderTextureCamera.targetTexture = null;
				}
				AMCameraFade._cf.renderTextureCamera = null;
			}
		}
	}

	public static void clearRenderTexture()
	{
		if (AMCameraFade._cf != null)
		{
			AMCameraFade._cf.clearTexture();
		}
	}

	public static void destroyAndReload(bool isPreview)
	{
		if (AMCameraFade._cf != null)
		{
			AMCameraFade._cf.destroyImmediate();
		}
		AMCameraFade._cf = null;
		AMCameraFade.getCameraFade(isPreview);
	}

	public static void destroyImmediateInstance()
	{
		if (AMCameraFade._cf != null)
		{
			AMCameraFade._cf.destroyImmediate();
		}
	}

	public static bool hasInstance()
	{
		return AMCameraFade._cf != null;
	}

	public static bool isPreview()
	{
		return AMCameraFade._cf != null && AMCameraFade._cf.preview;
	}

	public static void doShouldUpdateStill()
	{
		if (AMCameraFade._cf)
		{
			AMCameraFade._cf.cachedStillFrame = 0;
			AMCameraFade._cf.shouldUpdateStill = true;
		}
	}

	public static Vector2 getPositionAtAngle(int a, float padding)
	{
		a = (a % 360 + 360) % 360;
		Vector2 result = new Vector2(0f, 0f);
		float num = 0f - padding;
		float num2 = 1f + padding;
		float num3 = 0f - padding;
		float num4 = 1f + padding;
		float num5 = num2 - num;
		float num6 = num4 - num3;
		if (a >= 0 && a <= 45)
		{
			result.x = (float)a / 45f * (num5 / 2f) + num5 / 2f;
			result.y = num4;
		}
		else if (a <= 90)
		{
			result.x = num2;
			result.y = (1f - ((float)a - 45f) / 45f) * (num6 / 2f) + num6 / 2f;
		}
		else if (a <= 135)
		{
			result.x = num2;
			result.y = (1f - ((float)a - 90f) / 45f) * (num6 / 2f);
		}
		else if (a <= 180)
		{
			result.x = (1f - ((float)a - 135f) / 45f) * (num5 / 2f) + num5 / 2f;
			result.y = num3;
		}
		else if (a <= 225)
		{
			result.x = (1f - ((float)a - 180f) / 45f) * (num5 / 2f);
			result.y = num3;
		}
		else if (a <= 270)
		{
			result.x = num;
			result.y = ((float)a - 225f) / 45f * (num6 / 2f);
		}
		else if (a <= 315)
		{
			result.x = num;
			result.y = ((float)a - 270f) / 45f * (num6 / 2f) + num6 / 2f;
		}
		else if (a <= 360)
		{
			result.x = ((float)a - 315f) / 45f * (num5 / 2f);
			result.y = num4;
		}
		return result;
	}

	public void repaint()
	{
		this.OnGUI();
	}

	public void incrementKeepAlives()
	{
		this.keepAlives++;
		this.keepAliveAwake = false;
	}

	public void clearTexture()
	{
		if (this.renderTextureCamera)
		{
			this.renderTextureCamera.targetTexture = null;
			this.renderTextureCamera = null;
		}
	}

	public void clearTexture2D()
	{
		if (this.tex2d)
		{
			UnityEngine.Object.Destroy(this.tex2d);
			this.tex2d = null;
		}
	}

	private RenderTexture getRenderTexture()
	{
		if (!this.shouldUpdateRenderTexture && this._tex)
		{
			return this._tex;
		}
		this.shouldUpdateRenderTexture = false;
		if (Application.isPlaying)
		{
			if (this._tex)
			{
				UnityEngine.Object.Destroy(this._tex);
			}
			this.width = Screen.width;
			this.height = Screen.height;
		}
		else
		{
			if (this._tex)
			{
				UnityEngine.Object.DestroyImmediate(this._tex);
			}
			if (this.width > 0)
			{
				if (this.height > 0)
				{
					goto IL_E3;
				}
			}
			try
			{
				Rect mainGameViewPosition = AMCameraFade.GetMainGameViewPosition();
				this.width = (int)mainGameViewPosition.width;
				this.height = (int)mainGameViewPosition.height;
			}
			catch
			{
				this.width = 200;
				this.height = 100;
				this.shouldUpdateRenderTexture = true;
			}
		}
		IL_E3:
		this._tex = new RenderTexture(this.width, this.height, 24);
		return this._tex;
	}

	public static object GetMainGameView()
	{
		Type type = Type.GetType("UnityEditor.GameView,UnityEditor");
		MethodInfo method = type.GetMethod("GetMainGameView", BindingFlags.Static | BindingFlags.NonPublic);
		return method.Invoke(null, null);
	}

	public static Rect GetMainGameViewPosition()
	{
		object mainGameView = AMCameraFade.GetMainGameView();
		return (Rect)mainGameView.GetType().GetProperty("position").GetValue(mainGameView, null);
	}

	private static AMCameraFade _cf;

	private static Texture2D _blankTexture;

	private static Material _matIris;

	public bool deleteMe;

	public bool updateTexture;

	[HideInInspector]
	public int keepAlives;

	[HideInInspector]
	public bool keepAliveColor;

	[HideInInspector]
	public bool keepAlivePreview;

	[HideInInspector]
	public bool keepAliveAwake = true;

	[HideInInspector]
	public int mode;

	[HideInInspector]
	public float percent;

	public float value;

	[HideInInspector]
	public bool useRenderTexture;

	[HideInInspector]
	public Texture2D tex2d;

	[HideInInspector]
	public RenderTexture _tex;

	[HideInInspector]
	public float[] r;

	[HideInInspector]
	public Camera renderTextureCamera;

	[HideInInspector]
	public bool hasColorTex;

	[HideInInspector]
	public bool hasColorBG;

	[HideInInspector]
	public Color colorTex;

	[HideInInspector]
	public Color colorBG;

	[HideInInspector]
	public int width;

	[HideInInspector]
	public int height;

	[HideInInspector]
	public bool placeholder;

	[HideInInspector]
	public Texture2D irisShape;

	[HideInInspector]
	public Texture background;

	[HideInInspector]
	public int cachedStillFrame;

	[HideInInspector]
	public bool isReset;

	[HideInInspector]
	public bool shouldUpdateStill;

	[HideInInspector]
	public bool shouldUpdateRenderTexture;

	[HideInInspector]
	public bool preview;

	public static class Defaults
	{
		public static class Doors
		{
			public const float layout = 0f;

			public const float type = 0f;

			public const float focalXorY = 0.5f;
		}

		public static class VenetianBlinds
		{
			public const float layout = 0f;

			public const int numberOfBlinds = 5;
		}

		public static class IrisBox
		{
			public const float type = 0f;

			public const float focalX = 0.5f;

			public const float focalY = 0.5f;
		}

		public static class IrisRound
		{
			public const float type = 0f;

			public const float maxScale = 2.5f;

			public const float focalX = 0.5f;

			public const float focalY = 0.5f;
		}

		public static class IrisShape
		{
			public const float type = 0f;

			public const float maxScale = 6f;

			public const int rotateAmount = 50;

			public const float easeRotation = 0f;

			public const float focalX = 0.5f;

			public const float focalY = 0.5f;

			public const float pivotX = 0.5f;

			public const float pivotY = 0.5f;
		}

		public static class ShapeWipe
		{
			public const int angle = 0;

			public const float scale = 6f;

			public const float padding = 0f;

			public const float offsetStart = 3f;

			public const float offsetEnd = -3f;
		}

		public static class LinearWipe
		{
			public const int angle = 0;

			public const float padding = 0.25f;
		}

		public static class RadialWipe
		{
			public const float direction = 0f;

			public const int startingAngle = 0;

			public const float focalX = 0.5f;

			public const float focalY = 0.5f;
		}

		public static class WedgeWipe
		{
			public const int startingAngle = 0;

			public const float focalX = 0.5f;

			public const float focalY = 0.5f;
		}
	}
}
