UIRectTransformlLocalizeSupport.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using I2.Loc;
  3. using UnityEngine;
  4. [DisallowMultipleComponent]
  5. [RequireComponent(typeof(RectTransform))]
  6. public class UIRectTransformlLocalizeSupport : MonoBehaviour
  7. {
  8. private void Awake()
  9. {
  10. if (this.callAwake)
  11. {
  12. return;
  13. }
  14. this.callAwake = true;
  15. this.rectTrans = base.GetComponent<RectTransform>();
  16. if (this.rectTrans != null)
  17. {
  18. this.holdLeft = this.rectTrans.offsetMin.x;
  19. this.holdRight = this.rectTrans.offsetMax.x;
  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.rectTrans.offsetMin = new Vector2(this.holdLeft, this.rectTrans.offsetMin.y);
  38. this.rectTrans.offsetMax = new Vector2(this.holdRight, this.rectTrans.offsetMax.y);
  39. }
  40. else
  41. {
  42. this.Apply(this.overRidePropertys);
  43. if (this.languageOverRidePropertys != null)
  44. {
  45. foreach (UIRectTransformlLocalizeSupport.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(UIRectTransformlLocalizeSupport.OverRideProperty property)
  57. {
  58. if (!this.callAwake)
  59. {
  60. this.Awake();
  61. }
  62. this.rectTrans.offsetMin = ((!property.right.enabled) ? new Vector2(this.holdLeft, this.rectTrans.offsetMin.y) : new Vector2((float)property.right.value, this.rectTrans.offsetMin.y));
  63. this.rectTrans.offsetMax = ((!property.left.enabled) ? new Vector2(this.holdRight, this.rectTrans.offsetMax.y) : new Vector2((float)property.left.value, this.rectTrans.offsetMin.y));
  64. }
  65. [SerializeField]
  66. public UIRectTransformlLocalizeSupport.OverRideProperty overRidePropertys = default(UIRectTransformlLocalizeSupport.OverRideProperty);
  67. [SerializeField]
  68. public UIRectTransformlLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys;
  69. private float holdLeft;
  70. private float holdRight;
  71. private RectTransform rectTrans;
  72. private bool callAwake;
  73. [Serializable]
  74. public struct OverRideProperty
  75. {
  76. public UIRectTransformlLocalizeSupport.OverRideProperty.IntValue right;
  77. public UIRectTransformlLocalizeSupport.OverRideProperty.IntValue left;
  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 UIRectTransformlLocalizeSupport.OverRideProperty Property;
  90. }
  91. }