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

public class SceneSingleEffect : MonoBehaviour
{
	public void Awake()
	{
		this.effect_obj_dic_.Clear();
		this.effect_obj_dic_.Add("MVP", UTY.GetChildObject(base.gameObject, "MVPEffect", false));
		this.effect_obj_dic_.Add("CharaInfo", UTY.GetChildObject(base.gameObject, "CharacterIntroduction", false));
		this.effect_obj_dic_.Add("CharaInfo2", UTY.GetChildObject(base.gameObject, "CharacterIntroduction2", false));
		this.effect_obj_dic_.Add("VS", UTY.GetChildObject(base.gameObject, "VSEffect", false));
		this.effect_obj_dic_.Add("Win", UTY.GetChildObject(base.gameObject, "WinEffect", false));
		this.effect_obj_dic_.Add("BattleScroll", UTY.GetChildObject(base.gameObject, "BattleScroll", false));
		this.effect_obj_dic_.Add("Smoke", GameObject.Find("Smoke_Floor"));
		this.effect_obj_dic_.Add("SpotLight", GameObject.Find("Spot light"));
		this.effect_obj_dic_["Smoke"].SetActive(false);
		this.effect_obj_dic_["SpotLight"].SetActive(false);
	}

	public void Start()
	{
		this.adv_kag_ = GameMain.Instance.ScriptMgr.adv_kag;
		this.adv_kag_.kag.AddTagCallBack("stopeffect", new KagScript.KagTagCallBack(this.TagStopEffect));
		this.adv_kag_.kag.AddTagCallBack("startkamifubuki", new KagScript.KagTagCallBack(this.TagStartKamiFubuki));
		this.adv_kag_.kag.AddTagCallBack("startmvpeffect", new KagScript.KagTagCallBack(this.TagStartMvpEffect));
		this.adv_kag_.kag.AddTagCallBack("startcharainfoeffect", new KagScript.KagTagCallBack(this.TagStartCharaInfoEffect));
		this.adv_kag_.kag.AddTagCallBack("startvseffect", new KagScript.KagTagCallBack(this.TagStartVsEffect));
		this.adv_kag_.kag.AddTagCallBack("startwineffect", new KagScript.KagTagCallBack(this.TagStartWinEffect));
		this.adv_kag_.kag.AddTagCallBack("battlescroll", new KagScript.KagTagCallBack(this.TagBattleScroll));
		this.adv_kag_.kag.AddTagCallBack("smoke", new KagScript.KagTagCallBack(this.TagSmoke));
		this.adv_kag_.kag.AddTagCallBack("stagelightanime", new KagScript.KagTagCallBack(this.TagStageLightAnime));
		this.adv_kag_.kag.AddTagCallBack("spotlight", new KagScript.KagTagCallBack(this.TagSpotLight));
		this.adv_kag_.Exec();
	}

	public void OnPreFinalize()
	{
		this.adv_kag_ = null;
	}

	public void OnDestroy()
	{
		if (this.adv_kag_ != null)
		{
			if (this.adv_kag_.kag != null)
			{
				this.adv_kag_.kag.RemoveTagCallBack("stopeffect");
				this.adv_kag_.kag.RemoveTagCallBack("startkamifubuki");
				this.adv_kag_.kag.RemoveTagCallBack("startmvpeffect");
				this.adv_kag_.kag.RemoveTagCallBack("startcharainfoeffect");
				this.adv_kag_.kag.RemoveTagCallBack("startvseffect");
				this.adv_kag_.kag.RemoveTagCallBack("startwineffect");
				this.adv_kag_.kag.RemoveTagCallBack("battlescroll");
				this.adv_kag_.kag.RemoveTagCallBack("smoke");
				this.adv_kag_.kag.RemoveTagCallBack("stagelightanime");
				this.adv_kag_.kag.RemoveTagCallBack("spotlight");
			}
			this.adv_kag_ = null;
		}
	}

	public bool TagStopEffect(KagTagSupport tag_data)
	{
		foreach (KeyValuePair<string, GameObject> keyValuePair in this.effect_obj_dic_)
		{
			keyValuePair.Value.SetActive(false);
		}
		GameObject gameObject = GameObject.Find("__GameMain__/BG");
		if (gameObject != null && 0 < gameObject.transform.childCount)
		{
			GameObject childObject = UTY.GetChildObject(gameObject.transform.GetChild(0).gameObject, "PKamihubuki", false);
			if (childObject != null)
			{
				UnityEngine.Object.DestroyImmediate(childObject);
			}
		}
		return false;
	}

	public bool TagStartKamiFubuki(KagTagSupport tag_data)
	{
		GameObject gameObject = GameObject.Find("__GameMain__/BG");
		if (gameObject.transform.childCount <= 0)
		{
			return false;
		}
		GameObject gameObject2 = gameObject.transform.GetChild(0).gameObject;
		GameObject gameObject3 = Utility.CreatePrefab(gameObject, "Prefab/Particle/PKamihubuki", true);
		gameObject3.name = "PKamihubuki";
		Vector3 localPosition = gameObject3.transform.localPosition;
		localPosition.y = 3.5f;
		gameObject3.transform.localPosition = localPosition;
		gameObject3.transform.parent = gameObject2.transform;
		return false;
	}

	public bool TagStartMvpEffect(KagTagSupport tag_data)
	{
		bool flag = true;
		this.effect_obj_dic_["MVP"].SetActive(flag);
		if (flag)
		{
			GameObject gameObject = GameObject.Find("__GameMain__/BG/Salon(Clone)");
			if (gameObject != null)
			{
				GameObject gameObject2 = Utility.CreatePrefab(gameObject, "Prefab/Particle/PKamihubuki", true);
				Vector3 localPosition = gameObject2.transform.localPosition;
				localPosition.y = 3.5f;
				gameObject2.transform.localPosition = localPosition;
			}
		}
		return false;
	}

	public bool TagStartCharaInfoEffect(KagTagSupport tag_data)
	{
		return false;
	}

	public bool TagStartVsEffect(KagTagSupport tag_data)
	{
		this.effect_obj_dic_["VS"].SetActive(true);
		return false;
	}

	public bool TagStartWinEffect(KagTagSupport tag_data)
	{
		this.effect_obj_dic_["Win"].SetActive(true);
		return false;
	}

	public bool TagBattleScroll(KagTagSupport tag_data)
	{
		this.effect_obj_dic_["BattleScroll"].SetActive(tag_data.IsValid("on"));
		return false;
	}

	public bool TagSmoke(KagTagSupport tag_data)
	{
		bool flag = tag_data.IsValid("on");
		ParticleEmitter component = this.effect_obj_dic_["Smoke"].GetComponent<ParticleEmitter>();
		if (flag)
		{
			if (!component.gameObject.activeSelf)
			{
				component.gameObject.SetActive(true);
			}
			component.maxSize = 0.7f;
		}
		else
		{
			component.maxSize = 0f;
			if (tag_data.IsValid("forc"))
			{
				component.gameObject.SetActive(false);
			}
		}
		return false;
	}

	public bool TagStageLightAnime(KagTagSupport tag_data)
	{
		if (GameMain.Instance.BgMgr.GetBGName() != "Salon")
		{
			return false;
		}
		bool flag = tag_data.IsValid("on");
		Func<string, string, Animation> func = delegate(string obj_name, string anm_name)
		{
			GameObject childObject = UTY.GetChildObject(GameMain.Instance.BgMgr.current_bg_object, obj_name, false);
			Animation animation2;
			if (childObject.GetComponent<Animation>() == null)
			{
				animation2 = childObject.AddComponent<Animation>();
			}
			else
			{
				animation2 = childObject.GetComponent<Animation>();
			}
			if (animation2.GetClip(anm_name) == null)
			{
				animation2.AddClip((AnimationClip)UnityEngine.Object.Instantiate(Resources.Load("SceneSingleEffect/Anim/" + anm_name)), anm_name);
			}
			return animation2;
		};
		foreach (KeyValuePair<string, string> keyValuePair in new Dictionary<string, string>
		{
			{
				"Light01",
				"ALLway01_Light01"
			},
			{
				"Light02",
				"ALLway01_Light01"
			},
			{
				"Light03",
				"ALLway01_Light03"
			},
			{
				"Light04",
				"ALLway01_Light04"
			},
			{
				"Light05",
				"ALLway01_Light05"
			},
			{
				"Light06",
				"ALLway01_Light06"
			},
			{
				"Light07",
				"ALLway01_Light07"
			},
			{
				"Light08",
				"ALLway01_Light08"
			},
			{
				"Light09",
				"ALLway01_Light09"
			}
		})
		{
			Animation animation = func(keyValuePair.Key, keyValuePair.Value);
			if (flag)
			{
				animation.Play(keyValuePair.Value);
			}
			else
			{
				animation.Stop();
			}
		}
		return false;
	}

	public bool TagSpotLight(KagTagSupport tag_data)
	{
		Light component = this.effect_obj_dic_["SpotLight"].GetComponent<Light>();
		if (tag_data.IsValid("on"))
		{
			component.gameObject.SetActive(true);
		}
		else if (tag_data.IsValid("off"))
		{
			component.gameObject.SetActive(false);
		}
		Vector3 localPosition = component.transform.localPosition;
		if (tag_data.IsValid("px"))
		{
			localPosition.x = tag_data.GetTagProperty("px").AsReal();
		}
		if (tag_data.IsValid("py"))
		{
			localPosition.y = tag_data.GetTagProperty("py").AsReal();
		}
		if (tag_data.IsValid("pz"))
		{
			localPosition.z = tag_data.GetTagProperty("pz").AsReal();
		}
		component.transform.localPosition = localPosition;
		Vector3 eulerAngles = component.transform.localRotation.eulerAngles;
		if (tag_data.IsValid("rx"))
		{
			eulerAngles.x = tag_data.GetTagProperty("rx").AsReal();
		}
		if (tag_data.IsValid("ry"))
		{
			eulerAngles.y = tag_data.GetTagProperty("ry").AsReal();
		}
		if (tag_data.IsValid("rz"))
		{
			eulerAngles.z = tag_data.GetTagProperty("rz").AsReal();
		}
		if (tag_data.IsValid("rx") || tag_data.IsValid("ry") || tag_data.IsValid("rz"))
		{
			component.transform.localRotation = Quaternion.Euler(eulerAngles);
		}
		Color color = component.color;
		if (tag_data.IsValid("r"))
		{
			color.r = tag_data.GetTagProperty("r").AsReal();
		}
		if (tag_data.IsValid("g"))
		{
			color.g = tag_data.GetTagProperty("g").AsReal();
		}
		if (tag_data.IsValid("b"))
		{
			color.b = tag_data.GetTagProperty("b").AsReal();
		}
		component.color = color;
		if (tag_data.IsValid("range"))
		{
			component.range = tag_data.GetTagProperty("range").AsReal();
		}
		if (tag_data.IsValid("angle"))
		{
			component.spotAngle = tag_data.GetTagProperty("angle").AsReal();
		}
		if (tag_data.IsValid("intensity"))
		{
			component.intensity = tag_data.GetTagProperty("intensity").AsReal();
		}
		return false;
	}

	private ADVKagManager adv_kag_;

	private Dictionary<string, GameObject> effect_obj_dic_ = new Dictionary<string, GameObject>();
}
