VersionService.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. public class VersionService
  6. {
  7. private static int largeVersion = 1;
  8. private static int smallVersion = 1;
  9. static bool isInit = false;
  10. ///大版本号
  11. public static int LargeVersion
  12. {
  13. get
  14. {
  15. if(!isInit)
  16. {
  17. isInit = true;
  18. AnalysisVersionFile();
  19. }
  20. return largeVersion;
  21. }
  22. set
  23. {
  24. if (!isInit)
  25. {
  26. isInit = true;
  27. AnalysisVersionFile();
  28. }
  29. largeVersion = value;
  30. }
  31. }
  32. ///小版本号
  33. public static int SmallVersion
  34. {
  35. get
  36. {
  37. if (!isInit)
  38. {
  39. isInit = true;
  40. AnalysisVersionFile();
  41. }
  42. return smallVersion;
  43. }
  44. set
  45. {
  46. if (!isInit)
  47. {
  48. isInit = true;
  49. AnalysisVersionFile();
  50. }
  51. smallVersion = value;
  52. }
  53. }
  54. //生成版本文件
  55. public static void CreateVersionFile()
  56. {
  57. Dictionary<string, object> VersionData = new Dictionary<string, object>();
  58. VersionData.Add(HotUpdateManager.c_largeVersionKey, largeVersion);
  59. VersionData.Add(HotUpdateManager.c_smallVersonKey, smallVersion);
  60. EditorUtil.WriteStringByFile(
  61. PathTool.GetAbsolutePath(ResLoadLocation.Resource, HotUpdateManager.c_versionFileName + ".json"),
  62. FrameWork.Json.Serialize(VersionData));
  63. AssetDatabase.Refresh();
  64. }
  65. //解析版本号文件
  66. static void AnalysisVersionFile()
  67. {
  68. string version = ResourceIOTool.ReadStringByFile(PathTool.GetAbsolutePath(ResLoadLocation.Resource, HotUpdateManager.c_versionFileName + ".json"));
  69. Dictionary<string, object> VersionData = null;
  70. if (version == "")
  71. {
  72. VersionData = null;
  73. }
  74. else
  75. {
  76. VersionData = (Dictionary<string, object>)FrameWork.Json.Deserialize(version);
  77. }
  78. if (VersionData == null)
  79. {
  80. largeVersion = -1;
  81. smallVersion = -1;
  82. return;
  83. }
  84. if (VersionData.ContainsKey(HotUpdateManager.c_largeVersionKey))
  85. {
  86. largeVersion = int.Parse(VersionData[HotUpdateManager.c_largeVersionKey].ToString());
  87. }
  88. else
  89. {
  90. largeVersion = -1;
  91. }
  92. if (VersionData.ContainsKey(HotUpdateManager.c_smallVersonKey))
  93. {
  94. smallVersion = int.Parse(VersionData[HotUpdateManager.c_smallVersonKey].ToString());
  95. }
  96. else
  97. {
  98. smallVersion = -1;
  99. }
  100. }
  101. }