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

public class NoteEffect : NoteBase
{
	protected override void Update()
	{
		base.Update();
	}

	private IEnumerator EffectDelete()
	{
		float timer = 0f;
		for (;;)
		{
			if (!RhythmAction_Mgr.Instance.IsPause)
			{
				timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
				this.m_MySprite.width = (int)((float)this.m_FirstWidth * Mathf.Sin(90f * Mathf.Clamp01(timer / this.m_EffectTime) * 0.0174532924f));
				this.m_MySprite.height = (int)((float)this.m_FirstHeight * Mathf.Sin(90f * Mathf.Clamp01(timer / this.m_EffectTime) * 0.0174532924f));
				if (timer >= this.m_EffectTime + this.m_WaitTime)
				{
					if (this.m_AllEffectList.All((ParticleSystem effect) => !effect.isPlaying))
					{
						break;
					}
				}
			}
			yield return null;
		}
		foreach (ParticleSystem particle in this.m_AllEffectList)
		{
			RhythmAction_Mgr.Instance.RemoveParticleSystem(particle);
		}
		UnityEngine.Object.Destroy(base.gameObject);
		yield break;
		yield break;
	}

	public void Initialize(Dance_Note.Evaluation evalue, bool IsAppeal, int dotX, int dotY, Note_Mgr.EffecctType effect_type)
	{
		this.m_MyDotX = dotX;
		this.m_MyDotY = dotY;
		this.m_FirstWidth = this.m_MySprite.width;
		this.m_FirstHeight = this.m_MySprite.height;
		this.m_MySprite.width = 0;
		this.m_MySprite.height = 0;
		NoteEffect.EffectSetting use_setting = this.m_AllSettings.SingleOrDefault((NoteEffect.EffectSetting e) => e.Evalue == evalue);
		Action<GameObject, List<GameObject>> action = delegate(GameObject parent, List<GameObject> not_light)
		{
			if (!parent)
			{
				return;
			}
			parent.SetActive(true);
			IEnumerator enumerator = parent.transform.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					Transform transform = (Transform)obj;
					if ((DanceSetting.Settings.IsNoteEffectLight && !not_light.Contains(transform.gameObject)) || effect_type == Note_Mgr.EffecctType.Nothing || (effect_type == Note_Mgr.EffecctType.Few && !use_setting.NotFewEffect.Contains(transform.gameObject)))
					{
						transform.gameObject.SetActive(false);
					}
					else
					{
						ParticleSystem component = transform.GetComponent<ParticleSystem>();
						if (component)
						{
							RhythmAction_Mgr.Instance.AddParticleSystem(component);
							this.m_AllEffectList.Add(component);
						}
					}
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
		};
		if (IsAppeal)
		{
			action(this.m_AppealEffect, this.m_NotLightAppeal);
		}
		else
		{
			action(use_setting.EffectObj, use_setting.NotLight);
		}
		this.m_MySprite.spriteName = use_setting.TexName;
		base.Start();
		base.StartCoroutine(this.EffectDelete());
	}

	private const float m_NotAnimeSize = 0.25f;

	[SerializeField]
	private float m_EffectTime = 0.5f;

	[SerializeField]
	private float m_WaitTime = 0.15f;

	[SerializeField]
	private UISprite m_MySprite;

	[SerializeField]
	private NoteEffect.EffectSetting[] m_AllSettings;

	[SerializeField]
	[Header("アピール時表示するオブジェクト")]
	private GameObject m_AppealEffect;

	[SerializeField]
	private List<GameObject> m_NotLightAppeal = new List<GameObject>();

	private int m_FirstWidth;

	private int m_FirstHeight;

	private List<ParticleSystem> m_AllEffectList = new List<ParticleSystem>();

	[Serializable]
	private class EffectSetting
	{
		[Header("評価")]
		public Dance_Note.Evaluation Evalue;

		[Header("表示オブジェクト")]
		public GameObject EffectObj;

		[Header("軽量モードで残すもの")]
		public List<GameObject> NotLight = new List<GameObject>();

		[Header("小エフェクトのとき残すもの")]
		public List<GameObject> NotFewEffect = new List<GameObject>();

		[Header("表示画像名")]
		public string TexName;
	}
}
