LocalizeTarget_NGUI_Label.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public class LocalizeTarget_NGUI_Label : LocalizeTarget<UILabel>
  6. {
  7. static LocalizeTarget_NGUI_Label()
  8. {
  9. LocalizeTarget_NGUI_Label.AutoRegister();
  10. }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  12. private static void AutoRegister()
  13. {
  14. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UILabel, LocalizeTarget_NGUI_Label>
  15. {
  16. Name = "NGUI Label",
  17. Priority = 100
  18. });
  19. }
  20. public override eTermType GetPrimaryTermType(Localize cmp)
  21. {
  22. return eTermType.Text;
  23. }
  24. public override eTermType GetSecondaryTermType(Localize cmp)
  25. {
  26. return eTermType.UIFont;
  27. }
  28. public override bool CanUseSecondaryTerm()
  29. {
  30. return true;
  31. }
  32. public override bool AllowMainTermToBeRTL()
  33. {
  34. return true;
  35. }
  36. public override bool AllowSecondTermToBeRTL()
  37. {
  38. return false;
  39. }
  40. public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
  41. {
  42. primaryTerm = ((!this.mTarget) ? null : this.mTarget.text);
  43. secondaryTerm = ((!(this.mTarget.ambigiousFont != null)) ? string.Empty : this.mTarget.ambigiousFont.name);
  44. }
  45. public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
  46. {
  47. Font secondaryTranslatedObj = cmp.GetSecondaryTranslatedObj<Font>(ref mainTranslation, ref secondaryTranslation);
  48. if (secondaryTranslatedObj != null)
  49. {
  50. if (secondaryTranslatedObj != this.mTarget.ambigiousFont)
  51. {
  52. this.mTarget.ambigiousFont = secondaryTranslatedObj;
  53. }
  54. }
  55. else
  56. {
  57. UIFont secondaryTranslatedObj2 = cmp.GetSecondaryTranslatedObj<UIFont>(ref mainTranslation, ref secondaryTranslation);
  58. if (secondaryTranslatedObj2 != null && this.mTarget.ambigiousFont != secondaryTranslatedObj2)
  59. {
  60. this.mTarget.ambigiousFont = secondaryTranslatedObj2;
  61. }
  62. }
  63. if (this.mInitializeAlignment)
  64. {
  65. this.mInitializeAlignment = false;
  66. this.mAlignment_LTR = (this.mAlignment_RTL = this.mTarget.alignment);
  67. if (LocalizationManager.IsRight2Left && this.mAlignment_RTL == NGUIText.Alignment.Right)
  68. {
  69. this.mAlignment_LTR = NGUIText.Alignment.Left;
  70. }
  71. if (!LocalizationManager.IsRight2Left && this.mAlignment_LTR == NGUIText.Alignment.Left)
  72. {
  73. this.mAlignment_RTL = NGUIText.Alignment.Right;
  74. }
  75. }
  76. UIInput uiinput = NGUITools.FindInParents<UIInput>(this.mTarget.gameObject);
  77. if (uiinput != null && uiinput.label == this.mTarget)
  78. {
  79. if (mainTranslation != null && uiinput.defaultText != mainTranslation)
  80. {
  81. if (cmp.CorrectAlignmentForRTL && (uiinput.label.alignment == NGUIText.Alignment.Left || uiinput.label.alignment == NGUIText.Alignment.Right))
  82. {
  83. uiinput.label.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL);
  84. }
  85. uiinput.defaultText = mainTranslation;
  86. }
  87. }
  88. else if (mainTranslation != null && this.mTarget.text != mainTranslation)
  89. {
  90. if (cmp.CorrectAlignmentForRTL && (this.mTarget.alignment == NGUIText.Alignment.Left || this.mTarget.alignment == NGUIText.Alignment.Right))
  91. {
  92. this.mTarget.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL);
  93. }
  94. if (((!this.mTarget.useFloatSpacing && (this.mTarget.spacingX != 0 || this.mTarget.spacingY != 0)) || (this.mTarget.useFloatSpacing && (this.mTarget.floatSpacingX != 0f || this.mTarget.floatSpacingY != 0f))) && cmp.GetComponent<NGUILabelSpacingHold>() == null)
  95. {
  96. cmp.gameObject.AddComponent<NGUILabelSpacingHold>();
  97. }
  98. this.mTarget.overflowMethod = UILabel.Overflow.ShrinkContent;
  99. this.mTarget.text = mainTranslation;
  100. }
  101. }
  102. private NGUIText.Alignment mAlignment_RTL = NGUIText.Alignment.Right;
  103. private NGUIText.Alignment mAlignment_LTR = NGUIText.Alignment.Left;
  104. private bool mAlignmentWasRTL;
  105. private bool mInitializeAlignment = true;
  106. }
  107. }