LocalizeTarget_UnityStandard_AudioSource.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public class LocalizeTarget_UnityStandard_AudioSource : LocalizeTarget<AudioSource>
  6. {
  7. static LocalizeTarget_UnityStandard_AudioSource()
  8. {
  9. LocalizeTarget_UnityStandard_AudioSource.AutoRegister();
  10. }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  12. private static void AutoRegister()
  13. {
  14. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<AudioSource, LocalizeTarget_UnityStandard_AudioSource>
  15. {
  16. Name = "AudioSource",
  17. Priority = 100
  18. });
  19. }
  20. public override eTermType GetPrimaryTermType(Localize cmp)
  21. {
  22. return eTermType.AudioClip;
  23. }
  24. public override eTermType GetSecondaryTermType(Localize cmp)
  25. {
  26. return eTermType.Text;
  27. }
  28. public override bool CanUseSecondaryTerm()
  29. {
  30. return false;
  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.clip) ? string.Empty : this.mTarget.clip.name);
  43. secondaryTerm = null;
  44. }
  45. public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
  46. {
  47. bool flag = (this.mTarget.isPlaying || this.mTarget.loop) && Application.isPlaying;
  48. AudioClip clip = this.mTarget.clip;
  49. AudioClip audioClip = cmp.FindTranslatedObject<AudioClip>(mainTranslation);
  50. if (clip != audioClip)
  51. {
  52. this.mTarget.clip = audioClip;
  53. }
  54. if (flag && this.mTarget.clip)
  55. {
  56. this.mTarget.Play();
  57. }
  58. }
  59. }
  60. }