LocalizeTarget_NGUI_Sprite.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if NGUI
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. #if UNITY_EDITOR
  6. [UnityEditor.InitializeOnLoad]
  7. #endif
  8. public class LocalizeTarget_NGUI_Sprite : LocalizeTarget<UISprite>
  9. {
  10. static LocalizeTarget_NGUI_Sprite() { AutoRegister(); }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UISprite, LocalizeTarget_NGUI_Sprite>() { Name = "NGUI UISprite", Priority = 100 }); }
  12. public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Sprite; }
  13. public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.UIAtlas; }
  14. public override bool CanUseSecondaryTerm () { return true; }
  15. public override bool AllowMainTermToBeRTL () { return false; }
  16. public override bool AllowSecondTermToBeRTL () { return false; }
  17. public override void GetFinalTerms ( Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm )
  18. {
  19. primaryTerm = mTarget ? mTarget.spriteName : null;
  20. secondaryTerm = (mTarget.atlas as UIAtlas ? (mTarget.atlas as UIAtlas).name : string.Empty);
  21. }
  22. public override void DoLocalize ( Localize cmp, string mainTranslation, string secondaryTranslation )
  23. {
  24. if (mTarget.spriteName == mainTranslation)
  25. return;
  26. //--[ Localize Atlas ]----------
  27. UIAtlas newAtlas = cmp.GetSecondaryTranslatedObj<UIAtlas>(ref mainTranslation, ref secondaryTranslation);
  28. bool bChanged = false;
  29. if (newAtlas != null && ((mTarget.atlas as UIAtlas) != newAtlas))
  30. {
  31. mTarget.atlas = newAtlas;
  32. bChanged = true;
  33. }
  34. if (newAtlas==null)
  35. {
  36. NGUIAtlas newNGUIAtlas = cmp.GetSecondaryTranslatedObj<NGUIAtlas>(ref mainTranslation, ref secondaryTranslation);
  37. if (newAtlas != null && ((mTarget.atlas as NGUIAtlas) != newNGUIAtlas))
  38. {
  39. mTarget.atlas = newAtlas;
  40. bChanged = true;
  41. }
  42. }
  43. if (mTarget.spriteName != mainTranslation && mTarget.atlas.GetSprite(mainTranslation) != null)
  44. {
  45. mTarget.spriteName = mainTranslation;
  46. bChanged = true;
  47. }
  48. if (bChanged)
  49. mTarget.MakePixelPerfect();
  50. }
  51. }
  52. }
  53. #endif