LocalizationManager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Globalization;
  6. using System.Collections;
  7. namespace I2.Loc
  8. {
  9. public static partial class LocalizationManager
  10. {
  11. #region Variables: Misc
  12. #endregion
  13. public static void InitializeIfNeeded()
  14. {
  15. #if UNITY_EDITOR
  16. #if UNITY_2017_2_OR_NEWER
  17. UnityEditor.EditorApplication.playModeStateChanged -= OnEditorPlayModeStateChanged;
  18. UnityEditor.EditorApplication.playModeStateChanged += OnEditorPlayModeStateChanged;
  19. #else
  20. UnityEditor.EditorApplication.playmodeStateChanged -= OldOnEditorPlayModeStateChanged;
  21. UnityEditor.EditorApplication.playmodeStateChanged += OldOnEditorPlayModeStateChanged;
  22. #endif
  23. #endif
  24. if (string.IsNullOrEmpty(mCurrentLanguage) || Sources.Count == 0)
  25. {
  26. AutoLoadGlobalParamManagers();
  27. UpdateSources();
  28. SelectStartupLanguage();
  29. }
  30. }
  31. public static string GetVersion()
  32. {
  33. return "2.8.13 f2";
  34. }
  35. public static int GetRequiredWebServiceVersion()
  36. {
  37. return 5;
  38. }
  39. public static string GetWebServiceURL( LanguageSourceData source = null )
  40. {
  41. if (source != null && !string.IsNullOrEmpty(source.Google_WebServiceURL))
  42. return source.Google_WebServiceURL;
  43. InitializeIfNeeded();
  44. for (int i = 0; i < Sources.Count; ++i)
  45. if (Sources[i] != null && !string.IsNullOrEmpty(Sources[i].Google_WebServiceURL))
  46. return Sources[i].Google_WebServiceURL;
  47. return string.Empty;
  48. }
  49. #if UNITY_EDITOR
  50. #if UNITY_2017_2_OR_NEWER
  51. static void OnEditorPlayModeStateChanged( UnityEditor.PlayModeStateChange stateChange )
  52. {
  53. if (stateChange != UnityEditor.PlayModeStateChange.ExitingPlayMode)
  54. return;
  55. #else
  56. static void OldOnEditorPlayModeStateChanged()
  57. {
  58. if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
  59. return;
  60. #endif
  61. OnLocalizeEvent = null;
  62. foreach (var source in Sources)
  63. {
  64. source.LoadAllLanguages(true);
  65. }
  66. try
  67. {
  68. var tempPath = Application.temporaryCachePath;
  69. foreach (var file in System.IO.Directory.GetFiles(tempPath).Where(f => f.Contains("LangSource_") && f.EndsWith(".loc")))
  70. {
  71. System.IO.File.Delete(file);
  72. }
  73. }
  74. catch(System.Exception)
  75. {
  76. }
  77. }
  78. #endif
  79. }
  80. }