LocalizeTarget_UnityUI_RawImage.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace I2.Loc
  5. {
  6. #if UNITY_EDITOR
  7. [InitializeOnLoad]
  8. #endif
  9. public class LocalizeTarget_UnityUI_RawImage : LocalizeTarget<RawImage>
  10. {
  11. static LocalizeTarget_UnityUI_RawImage() { AutoRegister(); }
  12. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<RawImage, LocalizeTarget_UnityUI_RawImage> { Name = "RawImage", Priority = 100 }); }
  13. public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Texture; }
  14. public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Text; }
  15. public override bool CanUseSecondaryTerm() { return false; }
  16. public override bool AllowMainTermToBeRTL() { return false; }
  17. public override bool AllowSecondTermToBeRTL() { return false; }
  18. public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
  19. {
  20. primaryTerm = mTarget.mainTexture ? mTarget.mainTexture.name : "";
  21. secondaryTerm = null;
  22. }
  23. public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
  24. {
  25. Texture Old = mTarget.texture;
  26. if (Old == null || Old.name != mainTranslation)
  27. mTarget.texture = cmp.FindTranslatedObject<Texture>(mainTranslation);
  28. // If the old value is not in the translatedObjects, then unload it as it most likely was loaded from Resources
  29. //if (!HasTranslatedObject(Old))
  30. // Resources.UnloadAsset(Old);
  31. // In the editor, sometimes unity "forgets" to show the changes
  32. #if UNITY_EDITOR
  33. if (!Application.isPlaying)
  34. EditorUtility.SetDirty(mTarget);
  35. #endif
  36. }
  37. }
  38. }