LocalizationManager.cs 2.6 KB

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