LocalizeTarget_UnityStandard_TextMesh.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public class LocalizeTarget_UnityStandard_TextMesh : LocalizeTarget<TextMesh>
  6. {
  7. static LocalizeTarget_UnityStandard_TextMesh()
  8. {
  9. LocalizeTarget_UnityStandard_TextMesh.AutoRegister();
  10. }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  12. private static void AutoRegister()
  13. {
  14. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<TextMesh, LocalizeTarget_UnityStandard_TextMesh>
  15. {
  16. Name = "TextMesh",
  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.font.RequestCharactersInTexture(mainTranslation);
  72. this.mTarget.text = mainTranslation;
  73. }
  74. }
  75. private TextAlignment mAlignment_RTL = TextAlignment.Right;
  76. private TextAlignment mAlignment_LTR;
  77. private bool mAlignmentWasRTL;
  78. private bool mInitializeAlignment = true;
  79. }
  80. }