using System;
using I2.Loc;
using UnityEngine;

[DisallowMultipleComponent]
public class TransformLocalizeSupport : MonoBehaviour
{
	private void Awake()
	{
		if (this.callAwake)
		{
			return;
		}
		this.callAwake = true;
		this.holdPosition = base.transform.localPosition;
		this.holdRotation = base.transform.localRotation;
		this.holdScale = base.transform.localScale;
		LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
		LocalizationManager.OnLocalizeEvent += this.OnLocalize;
		this.OnLocalize();
	}

	public void OnDestroy()
	{
		LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
	}

	public void OnLocalize()
	{
		if (!this.callAwake)
		{
			this.Awake();
		}
		if (LocalizationManager.CurrentLanguageCode == "ja")
		{
			base.transform.localPosition = this.holdPosition;
			base.transform.localRotation = this.holdRotation;
			base.transform.localScale = this.holdScale;
		}
		else
		{
			this.Apply(this.overRidePropertys);
			if (this.languageOverRidePropertys != null)
			{
				foreach (TransformLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys)
				{
					if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode)
					{
						this.Apply(languageOverRideProperty.Property);
						break;
					}
				}
			}
		}
	}

	public void Apply(TransformLocalizeSupport.OverRideProperty property)
	{
		if (!this.callAwake)
		{
			this.Awake();
		}
		base.transform.localPosition = ((!property.position.enabled) ? this.holdPosition : property.position.value);
		base.transform.localRotation = ((!property.rotation.enabled) ? this.holdRotation : Quaternion.Euler(property.rotation.value));
		base.transform.localScale = ((!property.scale.enabled) ? this.holdScale : property.scale.value);
	}

	[SerializeField]
	public TransformLocalizeSupport.OverRideProperty overRidePropertys = default(TransformLocalizeSupport.OverRideProperty);

	[SerializeField]
	public TransformLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys;

	private Vector3 holdPosition;

	private Quaternion holdRotation;

	private Vector3 holdScale;

	private bool callAwake;

	[Serializable]
	public struct OverRideProperty
	{
		public TransformLocalizeSupport.OverRideProperty.Vector3Value position;

		public TransformLocalizeSupport.OverRideProperty.Vector3Value rotation;

		public TransformLocalizeSupport.OverRideProperty.Vector3Value scale;

		[Serializable]
		public struct Vector3Value
		{
			public bool enabled;

			public Vector3 value;
		}
	}

	[Serializable]
	public struct LanguageOverRideProperty
	{
		public string LanguageCode;

		public TransformLocalizeSupport.OverRideProperty Property;
	}
}
