123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using I2.Loc;
- using UnityEngine;
- [DisallowMultipleComponent]
- [RequireComponent(typeof(UIWidget))]
- public class UIWidgetlLocalizeSupport : MonoBehaviour
- {
- private void Awake()
- {
- if (this.callAwake)
- {
- return;
- }
- this.callAwake = true;
- this.widget = base.GetComponent<UIWidget>();
- if (this.widget != null)
- {
- this.holdWidth = this.widget.width;
- this.holdHeight = this.widget.height;
- 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.widget.width = this.holdWidth;
- this.widget.height = this.holdHeight;
- }
- else
- {
- this.Apply(this.overRidePropertys);
- if (this.languageOverRidePropertys != null)
- {
- foreach (UIWidgetlLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys)
- {
- if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode)
- {
- this.Apply(languageOverRideProperty.Property);
- break;
- }
- }
- }
- }
- }
- public void Apply(UIWidgetlLocalizeSupport.OverRideProperty property)
- {
- if (!this.callAwake)
- {
- this.Awake();
- }
- this.widget.width = ((!property.width.enabled) ? this.holdWidth : property.width.value);
- this.widget.height = ((!property.height.enabled) ? this.holdHeight : property.height.value);
- }
- [SerializeField]
- public UIWidgetlLocalizeSupport.OverRideProperty overRidePropertys = default(UIWidgetlLocalizeSupport.OverRideProperty);
- [SerializeField]
- public UIWidgetlLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys;
- private int holdWidth;
- private int holdHeight;
- private UIWidget widget;
- private bool callAwake;
- [Serializable]
- public struct OverRideProperty
- {
- public UIWidgetlLocalizeSupport.OverRideProperty.IntValue width;
- public UIWidgetlLocalizeSupport.OverRideProperty.IntValue height;
- [Serializable]
- public struct IntValue
- {
- public bool enabled;
- public int value;
- }
- }
- [Serializable]
- public struct LanguageOverRideProperty
- {
- public string LanguageCode;
- public UIWidgetlLocalizeSupport.OverRideProperty Property;
- }
- }
|