LocalizeTarget_UnityUI_Image.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace I2.Loc
  5. {
  6. public class LocalizeTarget_UnityUI_Image : LocalizeTarget<Image>
  7. {
  8. static LocalizeTarget_UnityUI_Image()
  9. {
  10. LocalizeTarget_UnityUI_Image.AutoRegister();
  11. }
  12. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  13. private static void AutoRegister()
  14. {
  15. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<Image, LocalizeTarget_UnityUI_Image>
  16. {
  17. Name = "Image",
  18. Priority = 100
  19. });
  20. }
  21. public override bool CanUseSecondaryTerm()
  22. {
  23. return false;
  24. }
  25. public override bool AllowMainTermToBeRTL()
  26. {
  27. return false;
  28. }
  29. public override bool AllowSecondTermToBeRTL()
  30. {
  31. return false;
  32. }
  33. public override eTermType GetPrimaryTermType(Localize cmp)
  34. {
  35. return (!(this.mTarget.sprite == null)) ? eTermType.Sprite : eTermType.Texture;
  36. }
  37. public override eTermType GetSecondaryTermType(Localize cmp)
  38. {
  39. return eTermType.Text;
  40. }
  41. public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
  42. {
  43. primaryTerm = ((!this.mTarget.mainTexture) ? string.Empty : this.mTarget.mainTexture.name);
  44. if (this.mTarget.sprite != null && this.mTarget.sprite.name != primaryTerm)
  45. {
  46. primaryTerm = primaryTerm + "." + this.mTarget.sprite.name;
  47. }
  48. secondaryTerm = null;
  49. }
  50. public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
  51. {
  52. Sprite sprite = this.mTarget.sprite;
  53. if (sprite == null || sprite.name != mainTranslation)
  54. {
  55. this.mTarget.sprite = cmp.FindTranslatedObject<Sprite>(mainTranslation);
  56. }
  57. }
  58. }
  59. }