using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Rendering;

public class DanceMain : MonoBehaviour
{
	public static string RecetJumpLabel { private get; set; }

	public List<Maid> DanceMaid
	{
		get
		{
			return this.m_listMaid;
		}
	}

	public Maid UserMaid
	{
		get
		{
			return this.m_maidUser;
		}
	}

	public bool IsDanceEnd { get; private set; }

	public Transform OvrCamTrans
	{
		get
		{
			return this.m_trOvrDummyCam;
		}
	}

	public float DepthFocalSize
	{
		get
		{
			return this.m_DepthFocalSize;
		}
		set
		{
			this.m_DepthFocalSize = value;
			if (RhythmAction_Mgr.Instance)
			{
				RhythmAction_Mgr.Instance.SetFocalSize(value);
			}
		}
	}

	public string GetFolderPathToBinaryData()
	{
		string binaryFolderName = this.BinaryFolderName;
		string text = Path.GetFileNameWithoutExtension(this.BinaryFolderName).ToLower();
		return "Assets/Resources/SceneDance/" + Path.GetFileNameWithoutExtension(this.BinaryFolderName).ToLower() + "/";
	}

	private void Awake()
	{
		this.m_boDebugDummyBody = false;
		NTime.Reset();
		Dictionary<string, string> tag_backup = GameMain.Instance.ScriptMgr.adv_kag.tag_backup;
		string strScriptLabel;
		if (tag_backup != null && tag_backup.TryGetValue("label", out strScriptLabel))
		{
			this.m_strScriptLabel = strScriptLabel;
		}
		NDebug.Assert(this.m_listDummyAnimChara.Count == this.m_listAnimName.Count, "m_listDummyAnimChara と m_listAnimName の数は同一でないといけません。");
		NDebug.Assert(this.m_AnimatorData != null, "AnimatorDataが外れています。");
		NDebug.Assert(this.m_listTestPreset.Count == this.m_listAnimName.Count, "プリセット数が不正です。");
		NDebug.Assert(!string.IsNullOrEmpty(this.m_strMasterAudioFileName), "マスター用MasterAudioFileNameが必要です。");
		bool flag = DanceMain.IsDanceRecet;
		flag |= (RhythmAction_Mgr.NowState == RhythmAction_Mgr.DanceState.Dance_Second);
		flag |= (RhythmAction_Mgr.NowDance == RhythmAction_Mgr.DanceType.Encore);
		flag |= RhythmAction_Mgr.IsVSDance;
		if (flag && !DanceMain.KaraokeMode)
		{
			DanceSelect.SelectMaidActive(DanceMain.SelectDanceData);
			DanceMain.IsDanceRecet = false;
		}
		if (this.time_line_binary_ == null)
		{
			this.maid_data_binary_ = new DanceObjectDataBinary();
			this.maid_item_binary_ = new DanceObjectDataBinary();
			this.maid_event_binary_ = new DanceObjectDataBinary();
			this.time_line_binary_ = new AWReadBinaryData();
			if (this.UseBinaryData)
			{
				string file_name = this.GetFolderPathToBinaryData() + "item_data.bytes";
				this.maid_item_binary_.ReadData(file_name);
				NDebug.Assert(this.m_listItemObject.Count == this.maid_item_binary_.datas.Length, "アイテム数がバイナリデータと不一致");
				this.maid_item_binary_.Restoration(false);
				for (int i = 0; i < this.m_listItemObject.Count; i++)
				{
					if (!(this.m_listItemObject[i] != null))
					{
						this.m_listItemObject[i] = this.maid_item_binary_.datas[i].obj;
					}
				}
				file_name = this.GetFolderPathToBinaryData() + "event_data.bytes";
				this.maid_event_binary_.ReadData(file_name);
				NDebug.Assert(this.m_listEventObject.Count == this.maid_event_binary_.datas.Length, "イベント数がバイナリデータと不一致");
				this.maid_event_binary_.Restoration(false);
				for (int j = 0; j < this.m_listEventObject.Count; j++)
				{
					if (!(this.m_listEventObject[j] != null))
					{
						this.m_listEventObject[j] = this.maid_event_binary_.datas[j].obj;
					}
				}
				file_name = this.GetFolderPathToBinaryData() + "maid_data.bytes";
				this.maid_data_binary_.ReadData(file_name);
				NDebug.Assert(this.m_listDummyAnimChara.Count == this.maid_data_binary_.datas.Length, "メイド数がバイナリデータと不一致");
				this.maid_data_binary_.Restoration(true);
				for (int k = 0; k < this.m_listDummyAnimChara.Count; k++)
				{
					if (!(this.m_listDummyAnimChara[k] != null))
					{
						this.m_listDummyAnimChara[k] = this.maid_data_binary_.datas[k].obj;
						this.m_listDebugObj.Add(this.m_listDummyAnimChara[k]);
					}
				}
				file_name = this.GetFolderPathToBinaryData() + "timeline_data.bytes";
				this.time_line_binary_.ReadFile(file_name);
				this.maid_item_binary_.AttachObject(this.m_AnimatorData.getTake(this.m_strPlayTakeName));
				this.maid_event_binary_.AttachObject(this.m_AnimatorData.getTake(this.m_strPlayTakeName));
			}
		}
		foreach (string str in this.m_listKuchiPakuFile)
		{
			TextAsset textAsset = Resources.Load("SceneDance/" + str) as TextAsset;
			NDebug.Assert(textAsset != null, "口パクパターンテキストファイルが開けません。" + str);
			string text = textAsset.text;
			NDebug.Assert(text.Length != 0, "口パクパターンファイル内が空です。" + str);
			text = Regex.Replace(text, "(\\r|\\n| )", string.Empty);
			this.m_listKuchiPattern.Add(text);
		}
		this.m_AnimatorData.playOnStart = null;
		this.m_AnimatorData.bAutoTimeUpdate = false;
		if (GameMain.Instance.VRMode && GameMain.Instance.CMSystem.GetTmpGenericFlag("ダンスOVRカメラタイプ") == 1)
		{
			this.m_trOvrDummyCam = new GameObject("OvrDummyDanceCam").transform;
			this.m_trOvrDummyCam.gameObject.AddComponent<Camera>().enabled = false;
			this.m_OvrCam = GameMain.Instance.OvrMgr.OvrCamera;
		}
		GameObject gameObject = GameObject.Find("RhythmAction_Mgr");
		if (!gameObject)
		{
			gameObject = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/RhythmAction_Mgr"));
		}
		if (!RhythmAction_Mgr.Instance)
		{
			gameObject.GetComponent<RhythmAction_Mgr>().InstanceInit();
		}
		for (int l = 0; l < this.m_listTestPreset.Count; l++)
		{
			Maid maid = GameMain.Instance.CharacterMgr.GetMaid(l);
			if (maid)
			{
				if (!this.m_maidUser)
				{
					this.m_maidUser = DanceSelect.SelectTopMaid;
				}
				maid.Visible = true;
			}
		}
		if (!this.m_maidUser)
		{
			this.m_maidUser = GameMain.Instance.CharacterMgr.GetMaid(0);
		}
		if (DanceMain.KaraokeMode)
		{
			return;
		}
		GameMain.Instance.CharacterMgr.ResetCharaPosAll();
		if (DanceMain.SelectDanceData != null)
		{
			for (int m = 0; m < DanceMain.SelectDanceData.select_chara_num; m++)
			{
				RhythmAction_Mgr.Instance.FactOrderList.Add(GameMain.Instance.CharacterMgr.GetMaid(m));
			}
		}
		if (RhythmAction_Mgr.NowDance != RhythmAction_Mgr.DanceType.BenchMark && DanceMain.SelectDanceData != null && DanceMain.SelectDanceData.maid_order.Count > 0)
		{
			List<Maid> list = new List<Maid>();
			for (int n = 0; n < DanceMain.SelectDanceData.maid_order.Count; n++)
			{
				list.Add(GameMain.Instance.CharacterMgr.GetMaid(n));
			}
			GameMain.Instance.CharacterMgr.DeactivateCharaAll();
			GameMain.Instance.CharacterMgr.DeactivateMaid(0);
			for (int num = 0; num < DanceMain.SelectDanceData.maid_order.Count; num++)
			{
				int index = DanceMain.SelectDanceData.maid_order[num];
				if (list[index])
				{
					GameMain.Instance.CharacterMgr.SetActiveMaid(list[index], num);
					list[index].Visible = true;
				}
			}
		}
		if (RhythmAction_Mgr.Instance.FactOrderList.Any((Maid e) => !e))
		{
			for (int num2 = 0; num2 < this.m_listTestPreset.Count; num2++)
			{
				Maid maid2 = GameMain.Instance.CharacterMgr.GetMaid(num2);
				if (!maid2)
				{
					maid2 = GameMain.Instance.CharacterMgr.AddStockMaid();
					GameMain.Instance.CharacterMgr.SetActiveMaid(maid2, num2);
					CharacterMgr.Preset preset;
					if (DanceMain.SelectDanceData != null && !string.IsNullOrEmpty(DanceMain.SelectDanceData.preset_name[num2]))
					{
						preset = GameMain.Instance.CharacterMgr.PresetLoadFromResources(DanceMain.SelectDanceData.preset_name[num2]);
					}
					else
					{
						preset = GameMain.Instance.CharacterMgr.PresetLoadFromResources(this.m_listTestPreset[num2]);
					}
					if (preset != null)
					{
						GameMain.Instance.CharacterMgr.PresetSet(maid2, preset);
					}
					this.m_listTempMaid.Add(maid2);
					maid2.Visible = true;
				}
			}
			for (int num3 = 0; num3 < DanceMain.SelectDanceData.maid_order.Count; num3++)
			{
				int index2 = DanceMain.SelectDanceData.maid_order[num3];
				if (!RhythmAction_Mgr.Instance.FactOrderList[index2])
				{
					RhythmAction_Mgr.Instance.FactOrderList[index2] = GameMain.Instance.CharacterMgr.GetMaid(num3);
				}
			}
		}
	}

	private void Start()
	{
		if (GameMain.Instance.VRMode)
		{
			GameObject gameObject = GameObject.Find("effect");
			if (gameObject != null)
			{
				ParticleSystem[] componentsInChildren = gameObject.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem particleSystem in componentsInChildren)
				{
					Renderer component = particleSystem.GetComponent<Renderer>();
					if (component != null)
					{
						component.shadowCastingMode = ShadowCastingMode.Off;
						component.receiveShadows = false;
					}
				}
			}
		}
		if (!DanceMain.KaraokeMode)
		{
			GameMain.Instance.BgMgr.DeleteBg();
		}
		GameMain.Instance.MainLight.Reset();
		GameMain.Instance.SoundMgr.StopBGM(0f);
		GameMain.Instance.MainCamera.gameObject.SetActive(true);
		if (!DanceMain.KaraokeMode)
		{
			GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, false);
		}
		for (int j = 0; j < this.m_listEventObject.Count; j++)
		{
			GameObject gameObject2 = this.m_listEventObject[j];
			NDebug.Assert(!this.m_htEventObj.ContainsKey(gameObject2.name), "listEventObjectに複数同じObjectを追加しようとしました。" + this.m_listEventObject[j].name);
			this.m_htEventObj.Add(gameObject2.name, gameObject2);
		}
		this.m_takeNow = this.m_AnimatorData.getTake(this.m_strPlayTakeName);
		NDebug.Assert(this.m_takeNow != null, "再生するテイク名PlayTakeNameが不正です。" + this.m_strPlayTakeName);
	}

	public void SetFace(int f_nMaidNo, string f_strFace)
	{
		RhythmAction_Mgr.Instance.SetTimeLineFace(f_nMaidNo, f_strFace);
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(f_nMaidNo);
		if (RhythmAction_Mgr.Instance.GetMaidFaceStop(f_nMaidNo))
		{
			return;
		}
		maid.FaceAnime(f_strFace, 1f, 0);
	}

	public void SetFaceBlend(int f_nMaidNo, string f_strFace)
	{
		RhythmAction_Mgr.Instance.SetTimeLineFaceBlend(f_nMaidNo, f_strFace);
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(f_nMaidNo);
		if (RhythmAction_Mgr.Instance.GetMaidFaceBlendStop(f_nMaidNo))
		{
			return;
		}
		maid.FaceBlend(f_strFace);
	}

	public void SetMaidVisible(int f_nMaidNo, bool visible)
	{
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(f_nMaidNo);
		maid.transform.localScale = ((!visible) ? Vector3.zero : Vector3.one);
	}

	public void SwitchObject(string f_strObjName, bool bEnable)
	{
		(this.m_htEventObj[f_strObjName] as GameObject).SetActive(bEnable);
	}

	public void EyeToCam(int f_nMaidNo, string f_strType)
	{
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(f_nMaidNo);
		try
		{
			maid.EyeToCamera((Maid.EyeMoveType)Enum.Parse(typeof(Maid.EyeMoveType), f_strType), 0f);
		}
		catch (Exception ex)
		{
			NDebug.Assert("EyeToCam 目線タイプ " + f_strType + " は不正です。\n" + ex.Message, false);
		}
	}

	public void FadeOut(float f_fTime)
	{
		GameMain.Instance.MainCamera.FadeOut(f_fTime, false, null, false, default(Color));
	}

	public void FadeIn(float f_fTime)
	{
		GameMain.Instance.MainCamera.FadeIn(f_fTime, false, null, false, true, default(Color));
	}

	private void ChangeObj(AMTake f_take, string f_strOldObjName, GameObject f_goNew)
	{
		AMTranslationTrack[] array = f_take.findTranslationTrack(f_strOldObjName);
		for (int i = 0; i < array.Length; i++)
		{
			array[i].changeObject(f_goNew.transform);
		}
		AMRotationTrack[] array2 = f_take.findRotationTrack(f_strOldObjName);
		for (int j = 0; j < array2.Length; j++)
		{
			array2[j].changeObject(f_goNew.transform);
		}
		AMPropertyTrack[] array3 = f_take.findPropertyTrack(f_strOldObjName);
		for (int k = 0; k < array3.Length; k++)
		{
			array3[k].changeObject(f_goNew);
		}
	}

	public void OnDestroy()
	{
		this.Uninit();
		Debug.Log("DanceMain::OnDestroy");
	}

	private void Uninit()
	{
		if (this.m_bFinished)
		{
			return;
		}
		if (RhythmAction_Mgr.Instance && DanceMain.KaraokeMode)
		{
			RhythmAction_Mgr.Instance.KaraokeEnd();
		}
		Debug.Log("DanceMain::Uninit");
		this.m_AnimatorData.StopLoop();
		if (GameMain.Instance.MainLight != null)
		{
			GameMain.Instance.MainLight.Reset();
		}
		if (GameMain.Instance.MainCamera != null)
		{
			GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
			GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
		}
		if (GameMain.Instance.SoundMgr != null)
		{
			GameMain.Instance.SoundMgr.StopBGM(0f);
		}
		if (GameMain.Instance.CharacterMgr != null)
		{
			GameMain.Instance.CharacterMgr.ResetCharaPosAll();
		}
		for (int i = 0; i < this.m_listMaid.Count; i++)
		{
			if (this.m_listMaid[i] != null)
			{
				this.m_listMaid[i].transform.localScale = Vector3.one;
				this.m_listMaid[i].StopKuchipakuPattern();
				this.m_listMaid[i].EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
			}
		}
		for (int j = 0; j < this.m_listItemObject.Count; j++)
		{
			if (this.m_listItemObject[j] != null)
			{
				UnityEngine.Object.DestroyImmediate(this.m_listItemObject[j]);
			}
		}
		this.m_listItemObject.Clear();
		for (int k = 0; k < this.m_listTempMaid.Count; k++)
		{
			GameMain.Instance.CharacterMgr.BanishmentMaid(this.m_listTempMaid[k]);
		}
		if (!DanceMain.KaraokeMode)
		{
			if (this.DanceMaid.Any((Maid maid) => maid != null))
			{
				GameMain.Instance.CharacterMgr.DeactivateCharaAll();
			}
			if (this.m_maidUser != null && this.m_maidUser != GameMain.Instance.CharacterMgr.GetMaid(0))
			{
				GameMain.Instance.CharacterMgr.DeactivateMaid(0);
				GameMain.Instance.CharacterMgr.SetActiveMaid(this.m_maidUser, 0);
			}
		}
		this.m_eMode = DanceMain.Mode.Finish;
		this.m_bFinished = true;
	}

	private void ToFinish()
	{
		this.IsDanceEnd = !this.IsForceDanceEnd;
		RhythmAction_Mgr.Instance.RhythmGame_End();
		this.Uninit();
		if (!DanceMain.IsDanceRecet)
		{
			DanceSelect.SetNextDance();
		}
		else
		{
			NDebug.Assert(!string.IsNullOrEmpty(DanceMain.RecetJumpLabel), "やりなおし時に飛ぶラベルが設定されてません");
		}
		Debug.Log("Dance ToFinish Script");
		if (!string.IsNullOrEmpty(this.m_strScriptLabel))
		{
			if (DanceMain.IsDanceRecet)
			{
				Debug.Log("OnEndScene JumpTo " + DanceMain.RecetJumpLabel);
				GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(DanceMain.RecetJumpLabel);
			}
			else
			{
				if (DanceMain.SelectDanceData != null)
				{
					GameMain.Instance.ScriptMgr.EvalScript("tf['dance_scene_name'] = '" + DanceMain.SelectDanceData.scene_name + "';");
				}
				Debug.Log("OnEndScene JumpTo " + this.m_strScriptLabel);
				GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_strScriptLabel);
			}
			GameMain.Instance.ScriptMgr.adv_kag.Exec();
		}
		Debug.Log("Dance Finish!!");
	}

	private IEnumerator LoadMotionScript()
	{
		if (this.m_AdjustScript.IndexOf(".ks") < 0)
		{
			this.m_AdjustScript += ".ks";
		}
		NDebug.Assert(!string.IsNullOrEmpty(this.m_ScriptLabel), string.Format("{0}の飛び先が未指定です。", this.m_AdjustScript));
		if (this.m_ScriptLabel.IndexOf("*") < 0)
		{
			this.m_ScriptLabel = "*" + this.m_ScriptLabel;
		}
		ScriptManager script_mgr = GameMain.Instance.ScriptMgr;
		script_mgr.StopMotionScript();
		script_mgr.is_motion_blend = true;
		script_mgr.LoadMotionScript(0, false, this.m_AdjustScript, this.m_ScriptLabel, string.Empty, string.Empty, false, true);
		float timer = 0f;
		while (timer <= this.m_LoadScriptTime)
		{
			timer += Time.deltaTime;
			yield return null;
		}
		script_mgr.StopMotionScript();
		this.m_eMode = DanceMain.Mode.LoadAnim;
		yield break;
	}

	private void Update()
	{
		if (this.m_eMode == DanceMain.Mode.ActiveCam)
		{
			if (GameMain.Instance.MainCamera.gameObject.activeSelf)
			{
				GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
				GameMain.Instance.MainCamera.SetCameraType(CameraMain.CameraType.Free);
				GameMain.Instance.MainCamera.SetControl(false);
				if (this.m_camDummyCamera != null)
				{
					if (!GameMain.Instance.VRMode)
					{
						AMTranslationTrack amtranslationTrack = this.m_takeNow.findTranslationTrack(this.m_camDummyCamera.gameObject.transform);
						amtranslationTrack.obj = GameMain.Instance.MainCamera.gameObject.transform;
						foreach (AMAction amaction in amtranslationTrack.cache)
						{
							AMTranslationAction amtranslationAction = (AMTranslationAction)amaction;
							amtranslationAction.obj = GameMain.Instance.MainCamera.gameObject.transform;
						}
						AMRotationTrack amrotationTrack = this.m_takeNow.findRotationTrack(this.m_camDummyCamera.gameObject.transform);
						amrotationTrack.obj = GameMain.Instance.MainCamera.gameObject.transform;
						foreach (AMAction amaction2 in amrotationTrack.cache)
						{
							AMRotationAction amrotationAction = (AMRotationAction)amaction2;
							amrotationAction.obj = GameMain.Instance.MainCamera.gameObject.transform;
						}
					}
					else if (GameMain.Instance.CMSystem.GetTmpGenericFlag("ダンスOVRカメラタイプ") != 0)
					{
						AMTranslationTrack amtranslationTrack2 = this.m_takeNow.findTranslationTrack(this.m_camDummyCamera.gameObject.transform);
						amtranslationTrack2.obj = this.m_trOvrDummyCam;
						foreach (AMAction amaction3 in amtranslationTrack2.cache)
						{
							AMTranslationAction amtranslationAction2 = (AMTranslationAction)amaction3;
							amtranslationAction2.obj = this.m_trOvrDummyCam;
						}
						AMRotationTrack amrotationTrack2 = this.m_takeNow.findRotationTrack(this.m_camDummyCamera.gameObject.transform);
						amrotationTrack2.obj = this.m_trOvrDummyCam;
						foreach (AMAction amaction4 in amrotationTrack2.cache)
						{
							AMRotationAction amrotationAction2 = (AMRotationAction)amaction4;
							amrotationAction2.obj = this.m_trOvrDummyCam;
						}
					}
					this.m_camDummyCamera.gameObject.SetActive(false);
				}
				if (!GameMain.Instance.VRMode)
				{
					this.ChangeObj(this.m_takeNow, "CameraMain", GameMain.Instance.MainCamera.gameObject);
				}
				else if (GameMain.Instance.CMSystem.GetTmpGenericFlag("ダンスOVRカメラタイプ") == 0)
				{
					if (!DanceMain.KaraokeMode)
					{
						GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0f, 1.16f, 0f), true);
						GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(180f, 0f), true);
						GameMain.Instance.MainCamera.SetDistance(5f, true);
					}
				}
				else
				{
					GameObject y = GameObject.Find("__GameMain__/Camera/CameraMain/CameraMain");
					AMBinaryDataBaseObject[] binary_data_list = this.time_line_binary_.binary_data_list;
					if (binary_data_list != null)
					{
						for (int i = 0; i < binary_data_list.Length; i++)
						{
							if (binary_data_list[i].obj == y)
							{
								binary_data_list[i].SetGameObject(this.m_trOvrDummyCam.gameObject);
							}
						}
					}
				}
				this.ChangeObj(this.m_takeNow, "MainDirectionalLight", GameMain.Instance.MainLight.gameObject);
				if (DanceMain.SelectDanceData == null || string.IsNullOrEmpty(DanceMain.SelectDanceData.bgm_file_name))
				{
					GameMain.Instance.SoundMgr.PlayDanceBGM(this.m_strMasterAudioFileName, 0f, true);
				}
				else
				{
					GameMain.Instance.SoundMgr.PlayDanceBGM(DanceMain.SelectDanceData.bgm_file_name + ".ogg", 0f, true);
				}
				AudioSource audioSourceBgm = GameMain.Instance.SoundMgr.GetAudioSourceBgm();
				audioSourceBgm.Stop();
				AMAudioTrack[] array = this.m_takeNow.findAudioTrack(this.m_strDummyAudioObjectName);
				foreach (AMAudioTrack amaudioTrack in array)
				{
					amaudioTrack.ChangeAudioSource(audioSourceBgm);
				}
				this.m_audioNew = audioSourceBgm;
				if (!this.m_boDebugDummyBody)
				{
					for (int k = 0; k < this.m_listAnimName.Count; k++)
					{
						this.m_listMaid.Add(GameMain.Instance.CharacterMgr.GetMaid(k));
					}
					for (int l = 0; l < this.m_listMaid.Count; l++)
					{
						this.m_listMaid[l].EyeToCamera(Maid.EyeMoveType.目だけ向ける, 0f);
					}
					NDebug.Assert(this.m_listKuchiPattern.Count == this.m_listMaid.Count, "メイド数と口パクパターン数が異なります。");
					for (int m = 0; m < this.m_listMaid.Count; m++)
					{
						this.m_listMaid[m].StartKuchipakuPattern(0f, this.m_listKuchiPattern[m], true);
					}
				}
				this.m_eMode = DanceMain.Mode.LoadChara;
			}
		}
		else if (this.m_eMode == DanceMain.Mode.LoadChara)
		{
			if (!GameMain.Instance.CharacterMgr.IsBusy() || this.m_listMaid.Count == 0)
			{
				if (!this.m_boDebugDummyBody)
				{
					int num = 1;
					for (;;)
					{
						string arg = "f";
						AMAnimationTrack amanimationTrack = this.m_takeNow.findAnimationTrack(arg + num);
						if (amanimationTrack == null)
						{
							break;
						}
						int num2 = num - 1;
						Maid maid = GameMain.Instance.CharacterMgr.GetMaid(num2);
						string name = maid.CrossFade(this.m_listAnimName[num2] + ".anm", false, false, false, 0f, 1f);
						Animation component = maid.body0.m_Bones.GetComponent<Animation>();
						component.Stop();
						amanimationTrack.obj = maid.body0.m_Bones;
						NDebug.Assert(amanimationTrack.cache.Count == 1, "キャラアニメーショントラックにはアクションを一つしか使えません。(開始と終了キーひとつのみ)");
						foreach (AMAction amaction5 in amanimationTrack.cache)
						{
							AMAnimationAction amanimationAction = (AMAnimationAction)amaction5;
							amanimationAction.amClip = component.GetClip(name);
							amanimationAction.obj = maid.body0.m_Bones;
						}
						if (this.UseFloorHitY)
						{
							maid.body0.SetBoneHitHeightY(this.m_fFloorY);
						}
						num++;
					}
					for (int n = 0; n < this.m_listDummyAnimChara.Count; n++)
					{
						Maid maid2 = GameMain.Instance.CharacterMgr.GetMaid(n);
						for (int num3 = 0; num3 < this.m_listItemObject.Count; num3++)
						{
							Transform transform = CMT.SearchObjObj(this.m_listDummyAnimChara[n].transform, this.m_listItemObject[num3].transform);
							if (transform != null)
							{
								Transform transform2 = transform;
								string name2 = transform2.parent.name;
								Transform parent = CMT.SearchObjName(maid2.gameObject.transform, name2, true);
								transform2.SetParent(parent, false);
							}
						}
					}
					for (int num4 = 0; num4 < this.m_listDebugObj.Count; num4++)
					{
						UnityEngine.Object.DestroyImmediate(this.m_listDebugObj[num4]);
					}
					this.m_listDebugObj.Clear();
				}
				if (string.IsNullOrEmpty(this.m_AdjustScript))
				{
					this.m_eMode = DanceMain.Mode.LoadAnim;
				}
				else
				{
					base.StartCoroutine(this.LoadMotionScript());
					this.m_eMode = DanceMain.Mode.LoadScript;
				}
			}
		}
		else if (this.m_eMode == DanceMain.Mode.LoadAnim)
		{
			this.m_AnimatorData.Play(this.m_takeNow.name, true, 0f, false, this.time_line_binary_.GetTrackIDList());
			this.m_fTakeStartRealTime = Time.realtimeSinceStartup;
			this.m_fNowRealTime = this.m_fTakeStartRealTime;
			this.m_eMode = DanceMain.Mode.Exec;
		}
		else if (this.m_eMode == DanceMain.Mode.Exec)
		{
			if (!RhythmAction_Mgr.Instance.IsPause)
			{
				float num5 = RhythmAction_Mgr.Instance.DanceDeltaTime;
				if (this.m_audioNew != null && this.m_audioNew.isPlaying)
				{
					float time = this.m_audioNew.time;
					for (int num6 = 0; num6 < this.m_listMaid.Count; num6++)
					{
						this.m_listMaid[num6].FoceKuchipakuUpdate(time);
					}
					if (this.m_bAudioFirst)
					{
						float num7 = time;
						num5 = Time.realtimeSinceStartup - this.m_fTakeStartRealTime;
						this.m_bAudioFirst = false;
						this.m_fOffsetTime = num7 - num5;
						RhythmAction_Mgr.Instance.RhythmGame_Start();
					}
				}
				this.m_fNowRealTime += num5;
			}
			if (this.IsForceDanceEnd || this.m_AnimatorData.takeName == null || this.IsDanceSkip || (DanceMain.KaraokeMode && Input.GetKeyDown(KeyCode.Return)))
			{
				this.ToFinish();
			}
		}
		else if (this.m_eMode == DanceMain.Mode.Finish)
		{
		}
		if (this.m_AnimatorData.takeName != null)
		{
			NTime.UpdateNowTime(this.m_fNowRealTime - this.m_fTakeStartRealTime + this.m_fOffsetTime);
			this.time_line_binary_.Update(NTime.time);
		}
		if (GameMain.Instance.VRMode && this.m_trOvrDummyCam != null && this.m_OvrCam != null)
		{
			this.m_OvrCam.SetPos(this.m_trOvrDummyCam.position);
			this.m_OvrCam.SetRotation(this.m_trOvrDummyCam.rotation.eulerAngles);
		}
	}

	private const string m_RhythmMgr_Path = "SceneDance/Rhythm_Action/Prefab/RhythmAction_Mgr";

	public static bool IsDanceRecet;

	public static DanceData SelectDanceData;

	public static bool KaraokeMode;

	private DanceMain.Mode m_eMode;

	public bool m_boDebugDummyBody;

	public Camera m_camDummyCamera;

	public List<GameObject> m_listDebugObj;

	public AnimatorData m_AnimatorData;

	public List<GameObject> m_listDummyAnimChara;

	public List<string> m_listAnimName;

	public List<GameObject> m_listEventObject;

	private Hashtable m_htEventObj = new Hashtable();

	public List<string> m_listTestPreset;

	public List<GameObject> m_listItemObject = new List<GameObject>();

	public List<string> m_listKuchiPakuFile = new List<string>();

	private List<string> m_listKuchiPattern = new List<string>();

	private List<Maid> m_listMaid = new List<Maid>();

	public string m_strDummyAudioObjectName;

	private AudioSource m_audioNew;

	public string m_strMasterAudioFileName;

	public string m_strPlayTakeName = "Take1";

	private AMTake m_takeNow;

	private string m_strScriptLabel = string.Empty;

	private List<Maid> m_listTempMaid = new List<Maid>();

	private Maid m_maidUser;

	[HideInInspector]
	public bool IsForceDanceEnd;

	[HideInInspector]
	public bool IsDanceSkip;

	private OvrCamera m_OvrCam;

	private Transform m_trOvrDummyCam;

	public bool UseBinaryData;

	public string BinaryFolderName;

	private DanceObjectDataBinary maid_data_binary_;

	private DanceObjectDataBinary maid_item_binary_;

	private DanceObjectDataBinary maid_event_binary_;

	private AWReadBinaryData time_line_binary_;

	[Header("物理境界を変更するか？")]
	public bool UseFloorHitY;

	public float m_fFloorY;

	[SerializeField]
	[Header("被写界深度の焦点")]
	private float m_DepthFocalSize = 1.2f;

	[SerializeField]
	[Header("マイク位置調整等に使うモーションスクリプト名")]
	private string m_AdjustScript = string.Empty;

	[SerializeField]
	private string m_ScriptLabel = string.Empty;

	[SerializeField]
	[Header("AdjustScript読み込みに要する時間")]
	private float m_LoadScriptTime = 3f;

	private bool m_bFinished;

	private float m_fNowRealTime;

	private float m_fTakeStartRealTime;

	private float m_fOffsetTime;

	private bool m_bAudioFirst = true;

	private enum Mode
	{
		ActiveCam,
		LoadChara,
		LoadAnim,
		Exec,
		Finish,
		LoadScript
	}
}
