using System; using I2.Loc; using UnityEngine; [DisallowMultipleComponent] [RequireComponent(typeof(RectTransform))] public class UIRectTransformlLocalizeSupport : MonoBehaviour { private void Awake() { if (this.callAwake) { return; } this.callAwake = true; this.rectTrans = base.GetComponent(); if (this.rectTrans != null) { this.holdLeft = this.rectTrans.offsetMin.x; this.holdRight = this.rectTrans.offsetMax.x; 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") { this.rectTrans.offsetMin = new Vector2(this.holdLeft, this.rectTrans.offsetMin.y); this.rectTrans.offsetMax = new Vector2(this.holdRight, this.rectTrans.offsetMax.y); } else { this.Apply(this.overRidePropertys); if (this.languageOverRidePropertys != null) { foreach (UIRectTransformlLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys) { if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode) { this.Apply(languageOverRideProperty.Property); break; } } } } } public void Apply(UIRectTransformlLocalizeSupport.OverRideProperty property) { if (!this.callAwake) { this.Awake(); } this.rectTrans.offsetMin = ((!property.right.enabled) ? new Vector2(this.holdLeft, this.rectTrans.offsetMin.y) : new Vector2((float)property.right.value, this.rectTrans.offsetMin.y)); this.rectTrans.offsetMax = ((!property.left.enabled) ? new Vector2(this.holdRight, this.rectTrans.offsetMax.y) : new Vector2((float)property.left.value, this.rectTrans.offsetMin.y)); } [SerializeField] public UIRectTransformlLocalizeSupport.OverRideProperty overRidePropertys = default(UIRectTransformlLocalizeSupport.OverRideProperty); [SerializeField] public UIRectTransformlLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys; private float holdLeft; private float holdRight; private RectTransform rectTrans; private bool callAwake; [Serializable] public struct OverRideProperty { public UIRectTransformlLocalizeSupport.OverRideProperty.IntValue right; public UIRectTransformlLocalizeSupport.OverRideProperty.IntValue left; [Serializable] public struct IntValue { public bool enabled; public int value; } } [Serializable] public struct LanguageOverRideProperty { public string LanguageCode; public UIRectTransformlLocalizeSupport.OverRideProperty Property; } }