LocalizeTarget_NGUI_Sprite.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public class LocalizeTarget_NGUI_Sprite : LocalizeTarget<UISprite>
  6. {
  7. static LocalizeTarget_NGUI_Sprite()
  8. {
  9. LocalizeTarget_NGUI_Sprite.AutoRegister();
  10. }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  12. private static void AutoRegister()
  13. {
  14. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UISprite, LocalizeTarget_NGUI_Sprite>
  15. {
  16. Name = "NGUI UISprite",
  17. Priority = 100
  18. });
  19. }
  20. public override eTermType GetPrimaryTermType(Localize cmp)
  21. {
  22. return eTermType.Sprite;
  23. }
  24. public override eTermType GetSecondaryTermType(Localize cmp)
  25. {
  26. return eTermType.UIAtlas;
  27. }
  28. public override bool CanUseSecondaryTerm()
  29. {
  30. return true;
  31. }
  32. public override bool AllowMainTermToBeRTL()
  33. {
  34. return false;
  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.spriteName);
  43. secondaryTerm = ((!(this.mTarget.atlas != null)) ? string.Empty : this.mTarget.atlas.name);
  44. }
  45. public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
  46. {
  47. if (this.mTarget.spriteName == mainTranslation)
  48. {
  49. return;
  50. }
  51. UIAtlas secondaryTranslatedObj = cmp.GetSecondaryTranslatedObj<UIAtlas>(ref mainTranslation, ref secondaryTranslation);
  52. bool flag = false;
  53. if (secondaryTranslatedObj != null && this.mTarget.atlas != secondaryTranslatedObj)
  54. {
  55. this.mTarget.atlas = secondaryTranslatedObj;
  56. flag = true;
  57. }
  58. if (this.mTarget.spriteName != mainTranslation && this.mTarget.atlas.GetSprite(mainTranslation) != null)
  59. {
  60. this.mTarget.spriteName = mainTranslation;
  61. flag = true;
  62. }
  63. if (flag)
  64. {
  65. this.mTarget.MakePixelPerfect();
  66. }
  67. }
  68. }
  69. }