using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ConfrontCutIn : MonoBehaviour
{
	private float m_FadeAlpha
	{
		get
		{
			return this.m_FadeSprite.color.a;
		}
		set
		{
			Color color = this.m_FadeSprite.color;
			color.a = value;
			this.m_FadeSprite.color = color;
		}
	}

	private float m_MydeltaTime
	{
		get
		{
			return Time.deltaTime * (float)this.m_TimeSpeed;
		}
	}

	private void Init(string end_label)
	{
		this.m_CutinBG.enabled = GameMain.Instance.VRMode;
		GameMain.Instance.SoundMgr.StopBGM(0f);
		GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
		UICamera.InputEnable = false;
		GameMain.Instance.BgMgr.DeleteBg();
		this.m_EndJumpLabel = end_label;
		GameMain.Instance.CharacterMgr.VisibleAll(false);
		this.m_VSText.gameObject.SetActive(false);
		foreach (ParticleSystem particleSystem in this.m_CutInEffect)
		{
			particleSystem.gameObject.SetActive(false);
		}
		this.m_FadeAlpha = 0f;
		this.m_PlayerSprite.sprite2D = ShootCutInTex.GetCutInTex(DanceBattle_Mgr.CharaType.Player, ShootCutInTex.CutInName.対峙演出);
		this.m_EnemySprite.sprite2D = ShootCutInTex.GetCutInTex(DanceBattle_Mgr.CharaType.Enemy, ShootCutInTex.CutInName.対峙演出);
		base.StartCoroutine(this.SpriteCutIn());
	}

	private void CheckJinglePlay(ConfrontCutIn.CutinEvent cutin_event, bool first)
	{
		if (cutin_event == this.m_JingleTiming && first == this.m_IsBeginPlay)
		{
			if (this.m_DelayTime > 0f)
			{
				base.Invoke("PlayJingle", this.m_DelayTime);
			}
			else
			{
				this.PlayJingle();
			}
		}
	}

	private void PlayJingle()
	{
		GameMain.Instance.SoundMgr.PlaySe(this.m_JingleSe, false);
	}

	private void Update()
	{
		this.m_EnemySprite.transform.localPosition = Vector3.right * (float)this.m_EnemySprite.width / 2f;
		this.m_TimeSpeed = ((!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightControl)) ? 1 : 2);
	}

	private IEnumerator SpriteCutIn()
	{
		float timer = 0f;
		bool enemy_cut = false;
		Vector3 player_first = Vector3.zero;
		Vector3 enemy_first = Vector3.zero;
		if (GameMain.Instance.VRMode)
		{
			player_first.x = (float)(-(float)this.m_UIRect_Width / 2);
			enemy_first.x = (float)(this.m_UIRect_Width / 2);
		}
		else
		{
			player_first.y = (enemy_first.y = (float)(Screen.height / 2));
			enemy_first.x = (float)(Screen.width * 2);
			enemy_first = UI_ScreenFitBase.PointToScreenPos(enemy_first);
			player_first.x = (float)(-(float)Screen.width);
			player_first = UI_ScreenFitBase.PointToScreenPos(player_first);
		}
		while (GameMain.Instance.MainCamera.IsFadeOut())
		{
			yield return null;
		}
		yield return new WaitForSeconds(this.m_CutInStart / (float)this.m_TimeSpeed);
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.PlayerCut, true);
		for (;;)
		{
			timer += this.m_MydeltaTime;
			if (!enemy_cut)
			{
				this.m_PlayerSprite.transform.parent.localPosition = Vector3.Lerp(player_first, Vector3.zero, this.TimeRate01(timer, this.m_CutInTime));
			}
			else
			{
				this.m_EnemySprite.transform.parent.localPosition = Vector3.Lerp(enemy_first, Vector3.zero, this.TimeRate01(timer, this.m_CutInTime));
			}
			this.m_CutinBG.transform.position = this.m_PlayerSprite.transform.position;
			if (timer > this.m_CutInTime)
			{
				if (!enemy_cut)
				{
					this.CheckJinglePlay(ConfrontCutIn.CutinEvent.PlayerCut, false);
				}
				else
				{
					this.CheckJinglePlay(ConfrontCutIn.CutinEvent.EnemyCut, false);
				}
				yield return new WaitForSeconds(this.m_CutInWait / (float)this.m_TimeSpeed);
				if (enemy_cut)
				{
					break;
				}
				this.CheckJinglePlay(ConfrontCutIn.CutinEvent.EnemyCut, true);
				enemy_cut = true;
				timer = 0f;
			}
			yield return null;
		}
		base.StartCoroutine(this.TextScaling());
		yield break;
		yield break;
	}

	private IEnumerator TextScaling()
	{
		this.m_VSText.gameObject.SetActive(true);
		float timer = 0f;
		Vector3 first = Vector3.zero;
		if (GameMain.Instance.VRMode)
		{
			first.y = (float)(this.m_UIRect_Width / 2);
		}
		else
		{
			first.x = (float)(Screen.width / 2);
			first.y = (float)(Screen.width / 2);
			first = UI_ScreenFitBase.PointToScreenPos(first);
			first.y *= -1f;
		}
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.TextZoom, true);
		for (;;)
		{
			timer += this.m_MydeltaTime;
			this.m_VSText.transform.localPosition = Vector3.Lerp(first, Vector3.zero, Mathf.Clamp01(timer / this.m_TextScaling));
			UIWidget vstext = this.m_VSText;
			int num = (int)Mathf.Lerp((float)this.m_TextMax, (float)this.m_TextMin, Mathf.Clamp01(timer / this.m_TextScaling));
			this.m_VSText.height = num;
			vstext.width = num;
			if (timer > this.m_TextScaling)
			{
				break;
			}
			yield return null;
		}
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.TextZoom, false);
		base.StartCoroutine(this.TextVibrate());
		yield break;
		yield break;
	}

	private IEnumerator TextVibrate()
	{
		float timer = 0f;
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.TextVibrate, true);
		for (;;)
		{
			timer += this.m_MydeltaTime;
			Vector3 vibe_vec = Vector3.zero;
			vibe_vec.x = (float)UnityEngine.Random.Range(-1, 1);
			vibe_vec.y = (float)UnityEngine.Random.Range(-1, 1);
			vibe_vec = vibe_vec.normalized * UnityEngine.Random.Range(0f, 1f) * this.m_VibrateRange;
			this.m_VSText.transform.localPosition = vibe_vec;
			if (timer > this.m_VibrateTime)
			{
				break;
			}
			yield return null;
		}
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.TextVibrate, false);
		this.m_VSText.transform.localPosition = Vector3.zero;
		base.StartCoroutine(this.FadeEffect());
		yield break;
		yield break;
	}

	private IEnumerator FadeEffect()
	{
		float timer = 0f;
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.ScreenFlash, true);
		for (;;)
		{
			timer += this.m_MydeltaTime;
			this.m_FadeAlpha = Mathf.Sin(Mathf.Clamp01(timer / this.m_FadeTime) * 180f * 0.0174532924f);
			if (timer > this.m_FadeTime)
			{
				break;
			}
			if (timer > this.m_FadeTime / 2f)
			{
				foreach (ParticleSystem particleSystem in this.m_CutInEffect)
				{
					particleSystem.gameObject.SetActive(true);
					if (!particleSystem.main.loop && !particleSystem.isPlaying)
					{
						particleSystem.Play();
					}
				}
				this.m_VSText.gameObject.SetActive(false);
			}
			yield return null;
		}
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.ScreenFlash, false);
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.EffectPlay, true);
		yield return new WaitForSeconds(this.m_EndWait / (float)this.m_TimeSpeed);
		NDebug.Assert(!string.IsNullOrEmpty(this.m_EndJumpLabel), "ConfrontCutIn.cs:対峙演出終了後に飛ぶラベルが設定されてません");
		this.CheckJinglePlay(ConfrontCutIn.CutinEvent.EffectPlay, false);
		GameMain.Instance.MainCamera.FadeOut(0.5f, false, new CameraMain.dgOnCompleteFade(this.CutInEnd), true, default(Color));
		yield break;
		yield break;
	}

	private void CutInEnd()
	{
		UnityEngine.Object.Destroy(base.gameObject);
		GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_EndJumpLabel);
		GameMain.Instance.ScriptMgr.adv_kag.Exec();
	}

	private float TimeRate01(float timer, float time_max)
	{
		return Mathf.Sin(Mathf.Clamp01(timer / time_max) * 90f * 0.0174532924f);
	}

	public static void CutInStart(string end_label)
	{
		GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/ConfrontCutIn"));
		gameObject.GetComponentInChildren<ConfrontCutIn>().Init(end_label);
	}

	private const string m_ConfrontObjPath = "SceneDance/Rhythm_Action/Prefab/ConfrontCutIn";

	private const int m_Magnification = 2;

	[SerializeField]
	[Header("ジングル再生するタイミング")]
	private ConfrontCutIn.CutinEvent m_JingleTiming;

	[SerializeField]
	[Header("イベントの開始時にならすかどうか")]
	private bool m_IsBeginPlay;

	[SerializeField]
	[Header("ジングルのSE名")]
	private string m_JingleSe;

	[SerializeField]
	[Header("ジングル再生時のDelay")]
	private float m_DelayTime;

	[SerializeField]
	[Header("")]
	private int m_UIRect_Width = 1920;

	[SerializeField]
	private UI2DSprite m_VSText;

	[SerializeField]
	[Header("プレイヤー画像")]
	private UI2DSprite m_PlayerSprite;

	[SerializeField]
	[Header("敵画像")]
	private UI2DSprite m_EnemySprite;

	[SerializeField]
	[Header("カットインエフェクト")]
	private List<ParticleSystem> m_CutInEffect = new List<ParticleSystem>();

	[SerializeField]
	[Header("フェード用画像")]
	private UISprite m_FadeSprite;

	[SerializeField]
	[Header("カットイン画像背景")]
	private UI2DSprite m_CutinBG;

	[SerializeField]
	[Header("全てのアニメーションが開始されるまでの待機時間")]
	private float m_CutInStart = 1f;

	[SerializeField]
	[Header("カットイン時間")]
	private float m_CutInTime = 0.5f;

	[SerializeField]
	[Header("カットイン後次の演出に行くまでの待機時間")]
	private float m_CutInWait = 0.5f;

	[SerializeField]
	[Header("テキストの拡縮時間")]
	private float m_TextScaling = 0.5f;

	[SerializeField]
	[Header("テキスト最大サイズ")]
	private int m_TextMax = 1024;

	[SerializeField]
	[Header("テキスト最小サイズ")]
	private int m_TextMin = 100;

	[SerializeField]
	[Header("テキスト振動量")]
	private float m_VibrateRange = 2.25f;

	[SerializeField]
	[Header("テキスト振動時間")]
	private float m_VibrateTime = 1f;

	[SerializeField]
	[Header("フェード時間")]
	private float m_FadeTime = 0.75f;

	[SerializeField]
	[Header("フェード終了後次の画面に行くまでの待機時間")]
	private float m_EndWait = 1f;

	private string m_EndJumpLabel = string.Empty;

	private int m_TimeSpeed = 1;

	private enum CutinEvent
	{
		PlayerCut,
		EnemyCut,
		TextZoom,
		TextVibrate,
		ScreenFlash,
		EffectPlay
	}
}
