UIWidgetlLocalizeSupport.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using I2.Loc;
  3. using UnityEngine;
  4. [DisallowMultipleComponent]
  5. [RequireComponent(typeof(UIWidget))]
  6. public class UIWidgetlLocalizeSupport : MonoBehaviour
  7. {
  8. private void Awake()
  9. {
  10. if (this.callAwake)
  11. {
  12. return;
  13. }
  14. this.callAwake = true;
  15. this.widget = base.GetComponent<UIWidget>();
  16. if (this.widget != null)
  17. {
  18. this.holdWidth = this.widget.width;
  19. this.holdHeight = this.widget.height;
  20. LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
  21. LocalizationManager.OnLocalizeEvent += this.OnLocalize;
  22. this.OnLocalize();
  23. }
  24. }
  25. public void OnDestroy()
  26. {
  27. LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
  28. }
  29. public void OnLocalize()
  30. {
  31. if (!this.callAwake)
  32. {
  33. this.Awake();
  34. }
  35. if (LocalizationManager.CurrentLanguageCode == "ja")
  36. {
  37. this.widget.width = this.holdWidth;
  38. this.widget.height = this.holdHeight;
  39. }
  40. else
  41. {
  42. this.Apply(this.overRidePropertys);
  43. if (this.languageOverRidePropertys != null)
  44. {
  45. foreach (UIWidgetlLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys)
  46. {
  47. if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode)
  48. {
  49. this.Apply(languageOverRideProperty.Property);
  50. break;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. public void Apply(UIWidgetlLocalizeSupport.OverRideProperty property)
  57. {
  58. if (!this.callAwake)
  59. {
  60. this.Awake();
  61. }
  62. this.widget.width = ((!property.width.enabled) ? this.holdWidth : property.width.value);
  63. this.widget.height = ((!property.height.enabled) ? this.holdHeight : property.height.value);
  64. }
  65. [SerializeField]
  66. public UIWidgetlLocalizeSupport.OverRideProperty overRidePropertys = default(UIWidgetlLocalizeSupport.OverRideProperty);
  67. [SerializeField]
  68. public UIWidgetlLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys;
  69. private int holdWidth;
  70. private int holdHeight;
  71. private UIWidget widget;
  72. private bool callAwake;
  73. [Serializable]
  74. public struct OverRideProperty
  75. {
  76. public UIWidgetlLocalizeSupport.OverRideProperty.IntValue width;
  77. public UIWidgetlLocalizeSupport.OverRideProperty.IntValue height;
  78. [Serializable]
  79. public struct IntValue
  80. {
  81. public bool enabled;
  82. public int value;
  83. }
  84. }
  85. [Serializable]
  86. public struct LanguageOverRideProperty
  87. {
  88. public string LanguageCode;
  89. public UIWidgetlLocalizeSupport.OverRideProperty Property;
  90. }
  91. }