HotSyncContent.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using ThirdParty.DownloadSystem;
  5. using UnityEngine;
  6. namespace ThirdParty
  7. {
  8. /// <summary>
  9. /// 和热更包里面同步的类容
  10. /// </summary>
  11. public class HotSyncContent
  12. {
  13. /// <summary>
  14. /// 资源服地址
  15. /// </summary>
  16. public static string AssetURL = "http://129.204.254.216:8080/resource/010test";
  17. public static string Currversion;
  18. public static bool isOpenHotFix;
  19. public static bool isOpenDllStreamingLoad;
  20. public static int assetsVer;
  21. private static string m_rootStreamingURL;
  22. public static string RootStreamingURL
  23. {
  24. get
  25. {
  26. m_rootStreamingURL = Application.streamingAssetsPath;
  27. #if UNITY_EDITOR
  28. #elif UNITY_IPHONE
  29. m_rootStreamingURL = "file://" + m_rootStreamingURL;
  30. #endif
  31. return m_rootStreamingURL;
  32. }
  33. }
  34. // #if UNITY_EDITOR
  35. // public static string platform = "Android";
  36. // // public static string platform = "PC";
  37. // #elif UNITY_IOS
  38. /// <summary>
  39. /// 1= 本地模式
  40. /// </summary>
  41. public static int loadType;
  42. #if UNITY_IOS
  43. public static string platform = "iOS";
  44. #elif UNITY_ANDROID
  45. public static string platform = "Android";
  46. #else
  47. public static string platform = "Android";
  48. #endif
  49. public static IDownloadUI DownloadUI;
  50. /// <summary>
  51. ///应用程序外部资源路径存放路径(热更新资源路径)
  52. /// </summary>
  53. public static string AppHotfixResPath
  54. {
  55. get
  56. {
  57. if (!Directory.Exists($"{Application.persistentDataPath}/Dll/"))
  58. {
  59. Debug.Log("创建目录:" + $"{Application.persistentDataPath}/Dll/");
  60. Directory.CreateDirectory($"{Application.persistentDataPath}/Dll/");
  61. }
  62. return $"{Application.persistentDataPath}/Dll/";
  63. }
  64. }
  65. /// <summary>
  66. /// 先从热更路径读取(表示已经热更过),在从内部路径读取(Application.streamingAssetsPath不能用File.Exists判断,无效)
  67. /// </summary>
  68. /// <param name="resourceName"></param>
  69. /// <returns></returns>
  70. public static string GetResPath(string resourceName)
  71. {
  72. string p = Path.Combine(AppHotfixResPath, resourceName);
  73. if (!File.Exists(p))
  74. {
  75. p = Path.Combine(Application.streamingAssetsPath, resourceName);
  76. }
  77. return p;
  78. }
  79. public static string GetWebRequestPath(string resourceName)
  80. {
  81. string p = GetResPath(resourceName);
  82. // webRequest要加file://
  83. if (!p.Contains("://"))
  84. {
  85. p = "file://" + p;
  86. }
  87. return p;
  88. }
  89. public static string FormatSpeed(float kbPerSecond)
  90. {
  91. const float ThresholdMB = 1024f;
  92. if (kbPerSecond >= ThresholdMB)
  93. {
  94. float mbPerSecond = kbPerSecond / 1000f;
  95. return $"{mbPerSecond:F2} MB/s";
  96. }
  97. else
  98. {
  99. return $"{kbPerSecond:F2} KB/s";
  100. }
  101. }
  102. public static string GetDllWebRequestPath(string resourceName)
  103. {
  104. string p = Path.Combine(AppHotfixResPath, resourceName);
  105. if (!File.Exists(p))
  106. {
  107. p = Path.Combine(RootStreamingURL + "/Dll/", resourceName);
  108. }
  109. #if !UNITY_EDITOR
  110. // webRequest要加file://
  111. if (!p.Contains("://"))
  112. {
  113. p = "file://" + p;
  114. }
  115. #endif
  116. return p;
  117. }
  118. /// <summary>
  119. /// 需要热更的的dll资源
  120. /// </summary>
  121. public static List<string> HotFixDll { get; } = new List<string>()
  122. {
  123. "init", //这个是进入热更场景的入口
  124. "Fort23.Proto.dll",
  125. "Fort23.Core.dll",
  126. "Fort23.GameData.dll",
  127. "Fort23.CombatCore.dll",
  128. "Fort23.UTool.dll",
  129. "Fort23.Combat.dll",
  130. "Fort23.Mono.dll",
  131. "spine-unity.dll",
  132. "spine-timeline.dll",
  133. "Assembly-CSharp.dll",
  134. };
  135. /// <summary>
  136. /// 需要补充元数据的泛型函数实例化的dll(注意,不要把热更dll放在这里了。)
  137. /// </summary>
  138. public static List<string> AOTMetaAssemblyNames { get; } = new List<string>()
  139. {
  140. "mscorlib.dll",
  141. "System.dll",
  142. "System.Core.dll",
  143. "spine-csharp.dll",
  144. "Newtonsoft.Json.dll",
  145. "Unity.Timeline.dll",
  146. "UnityEngine.CoreModule.dll",
  147. "ThirdParty.dll"
  148. };
  149. }
  150. // [Serializable]
  151. // public class AssetMD5Info
  152. // {
  153. // public List<MD5FileInfo> fileInfo;
  154. // }
  155. //
  156. // [Serializable]
  157. // public class MD5FileInfo
  158. // {
  159. // public string fileName;
  160. // public string md5;
  161. //
  162. // public long size;
  163. //
  164. // // TODO 暂时不验证
  165. // public string md5Verification;
  166. // }
  167. }