LocalizeTarget_UnityStandard_Child.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public class LocalizeTarget_UnityStandard_Child : LocalizeTarget<GameObject>
  6. {
  7. static LocalizeTarget_UnityStandard_Child()
  8. {
  9. LocalizeTarget_UnityStandard_Child.AutoRegister();
  10. }
  11. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  12. private static void AutoRegister()
  13. {
  14. LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Child
  15. {
  16. Name = "Child",
  17. Priority = 200
  18. });
  19. }
  20. public override bool IsValid(Localize cmp)
  21. {
  22. return cmp.transform.childCount > 1;
  23. }
  24. public override eTermType GetPrimaryTermType(Localize cmp)
  25. {
  26. return eTermType.GameObject;
  27. }
  28. public override eTermType GetSecondaryTermType(Localize cmp)
  29. {
  30. return eTermType.Text;
  31. }
  32. public override bool CanUseSecondaryTerm()
  33. {
  34. return false;
  35. }
  36. public override bool AllowMainTermToBeRTL()
  37. {
  38. return false;
  39. }
  40. public override bool AllowSecondTermToBeRTL()
  41. {
  42. return false;
  43. }
  44. public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
  45. {
  46. primaryTerm = cmp.name;
  47. secondaryTerm = null;
  48. }
  49. public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
  50. {
  51. if (string.IsNullOrEmpty(mainTranslation))
  52. {
  53. return;
  54. }
  55. Transform transform = cmp.transform;
  56. string text = mainTranslation;
  57. int num = mainTranslation.LastIndexOfAny(LanguageSource.CategorySeparators);
  58. if (num >= 0)
  59. {
  60. text = text.Substring(num + 1);
  61. }
  62. for (int i = 0; i < transform.childCount; i++)
  63. {
  64. Transform child = transform.GetChild(i);
  65. child.gameObject.SetActive(child.name == text);
  66. }
  67. }
  68. }
  69. }