LocalizeTarget_UnityStandard_GUIText.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public class LocalizeTarget_UnityStandard_GUIText : LocalizeTarget<GUIText>
  6. {
  7. static LocalizeTarget_UnityStandard_GUIText()
  8. {
  9. LocalizeTarget_UnityStandard_GUIText.AutoRegister();
  10. }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  12. private static void AutoRegister()
  13. {
  14. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<GUIText, LocalizeTarget_UnityStandard_GUIText>
  15. {
  16. Name = "GUIText",
  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.Font;
  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 = ((!string.IsNullOrEmpty(Secondary) || !(this.mTarget.font != null)) ? null : this.mTarget.font.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 && this.mTarget.font != secondaryTranslatedObj)
  49. {
  50. this.mTarget.font = secondaryTranslatedObj;
  51. }
  52. if (this.mInitializeAlignment)
  53. {
  54. this.mInitializeAlignment = false;
  55. this.mAlignment_LTR = (this.mAlignment_RTL = this.mTarget.alignment);
  56. if (LocalizationManager.IsRight2Left && this.mAlignment_RTL == TextAlignment.Right)
  57. {
  58. this.mAlignment_LTR = TextAlignment.Left;
  59. }
  60. if (!LocalizationManager.IsRight2Left && this.mAlignment_LTR == TextAlignment.Left)
  61. {
  62. this.mAlignment_RTL = TextAlignment.Right;
  63. }
  64. }
  65. if (mainTranslation != null && this.mTarget.text != mainTranslation)
  66. {
  67. if (cmp.CorrectAlignmentForRTL && this.mTarget.alignment != TextAlignment.Center)
  68. {
  69. this.mTarget.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL);
  70. }
  71. this.mTarget.text = mainTranslation;
  72. }
  73. }
  74. private TextAlignment mAlignment_RTL = TextAlignment.Right;
  75. private TextAlignment mAlignment_LTR;
  76. private bool mAlignmentWasRTL;
  77. private bool mInitializeAlignment = true;
  78. }
  79. }