HotSyncContent.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 GetDllWebRequestPath(string resourceName)
  90. {
  91. string p = Path.Combine(AppHotfixResPath, resourceName);
  92. if (!File.Exists(p))
  93. {
  94. p = Path.Combine(RootStreamingURL + "/Dll/", resourceName);
  95. }
  96. #if !UNITY_EDITOR
  97. // webRequest要加file://
  98. if (!p.Contains("://"))
  99. {
  100. p = "file://" + p;
  101. }
  102. #endif
  103. return p;
  104. }
  105. /// <summary>
  106. /// 需要热更的的dll资源
  107. /// </summary>
  108. public static List<string> HotFixDll { get; } = new List<string>()
  109. {
  110. "init", //这个是进入热更场景的入口
  111. "Fort23.Proto.dll",
  112. "Fort23.Core.dll",
  113. "Fort23.GameData.dll",
  114. "Fort23.CombatCore.dll",
  115. "Fort23.UTool.dll",
  116. "Fort23.Combat.dll",
  117. "Fort23.Mono.dll",
  118. "spine-unity.dll",
  119. "spine-timeline.dll",
  120. "Assembly-CSharp.dll",
  121. };
  122. /// <summary>
  123. /// 需要补充元数据的泛型函数实例化的dll(注意,不要把热更dll放在这里了。)
  124. /// </summary>
  125. public static List<string> AOTMetaAssemblyNames { get; } = new List<string>()
  126. {
  127. "mscorlib.dll",
  128. "System.dll",
  129. "System.Core.dll",
  130. "spine-csharp.dll",
  131. "Newtonsoft.Json.dll",
  132. "Unity.Timeline.dll",
  133. "UnityEngine.CoreModule.dll",
  134. "ThirdParty.dll"
  135. };
  136. }
  137. // [Serializable]
  138. // public class AssetMD5Info
  139. // {
  140. // public List<MD5FileInfo> fileInfo;
  141. // }
  142. //
  143. // [Serializable]
  144. // public class MD5FileInfo
  145. // {
  146. // public string fileName;
  147. // public string md5;
  148. //
  149. // public long size;
  150. //
  151. // // TODO 暂时不验证
  152. // public string md5Verification;
  153. // }
  154. }