YooAssetSettingsData.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System.IO;
  2. using UnityEngine;
  3. namespace YooAsset
  4. {
  5. public static class YooAssetSettingsData
  6. {
  7. #if UNITY_EDITOR
  8. [UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
  9. private static void OnRuntimeInitialize()
  10. {
  11. _setting = null;
  12. }
  13. #endif
  14. private static YooAssetSettings _setting = null;
  15. internal static YooAssetSettings Setting
  16. {
  17. get
  18. {
  19. if (_setting == null)
  20. LoadSettingData();
  21. return _setting;
  22. }
  23. }
  24. /// <summary>
  25. /// 加载配置文件
  26. /// </summary>
  27. private static void LoadSettingData()
  28. {
  29. _setting = Resources.Load<YooAssetSettings>("YooAssetSettings");
  30. if (_setting == null)
  31. {
  32. YooLogger.Log("YooAsset use default settings.");
  33. _setting = ScriptableObject.CreateInstance<YooAssetSettings>();
  34. }
  35. else
  36. {
  37. YooLogger.Log("YooAsset use user settings.");
  38. }
  39. }
  40. /// <summary>
  41. /// 获取YooAsset文件夹名称
  42. /// </summary>
  43. public static string GetDefaultYooFolderName()
  44. {
  45. return Setting.DefaultYooFolderName;
  46. }
  47. /// <summary>
  48. /// 获取构建报告文件名
  49. /// </summary>
  50. public static string GetBuildReportFileName(string packageName, string packageVersion)
  51. {
  52. if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
  53. return $"{packageName}_{packageVersion}.report";
  54. else
  55. return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.report";
  56. }
  57. /// <summary>
  58. /// 获取清单文件完整名称
  59. /// </summary>
  60. public static string GetManifestBinaryFileName(string packageName, string packageVersion)
  61. {
  62. if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
  63. return $"{packageName}_{packageVersion}.bytes";
  64. else
  65. return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.bytes";
  66. }
  67. /// <summary>
  68. /// 获取清单文件完整名称
  69. /// </summary>
  70. public static string GetManifestJsonFileName(string packageName, string packageVersion)
  71. {
  72. if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
  73. return $"{packageName}_{packageVersion}.json";
  74. else
  75. return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.json";
  76. }
  77. /// <summary>
  78. /// 获取包裹的哈希文件完整名称
  79. /// </summary>
  80. public static string GetPackageHashFileName(string packageName, string packageVersion)
  81. {
  82. if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
  83. return $"{packageName}_{packageVersion}.hash";
  84. else
  85. return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.hash";
  86. }
  87. /// <summary>
  88. /// 获取包裹的版本文件完整名称
  89. /// </summary>
  90. public static string GetPackageVersionFileName(string packageName)
  91. {
  92. if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
  93. return $"{packageName}.version";
  94. else
  95. return $"{Setting.PackageManifestPrefix}_{packageName}.version";
  96. }
  97. #region 路径相关
  98. /// <summary>
  99. /// 获取YOO的编辑器下缓存文件根目录
  100. /// </summary>
  101. internal static string GetYooEditorCacheRoot()
  102. {
  103. if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
  104. {
  105. string projectPath = Path.GetDirectoryName(Application.dataPath);
  106. projectPath = PathUtility.RegularPath(projectPath);
  107. return projectPath;
  108. }
  109. else
  110. {
  111. // 注意:为了方便调试查看,编辑器下把存储目录放到项目根目录下。
  112. string projectPath = Path.GetDirectoryName(Application.dataPath);
  113. projectPath = PathUtility.RegularPath(projectPath);
  114. return PathUtility.Combine(projectPath, Setting.DefaultYooFolderName);
  115. }
  116. }
  117. /// <summary>
  118. /// 获取YOO的PC平台缓存文件根目录
  119. /// </summary>
  120. internal static string GetYooStandaloneWinCacheRoot()
  121. {
  122. if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
  123. return Application.dataPath;
  124. else
  125. return PathUtility.Combine(Application.dataPath, Setting.DefaultYooFolderName);
  126. }
  127. /// <summary>
  128. /// 获取YOO的Linux平台缓存文件根目录
  129. /// </summary>
  130. internal static string GetYooStandaloneLinuxCacheRoot()
  131. {
  132. if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
  133. return Application.dataPath;
  134. else
  135. return PathUtility.Combine(Application.dataPath, Setting.DefaultYooFolderName);
  136. }
  137. /// <summary>
  138. /// 获取YOO的Mac平台缓存文件根目录
  139. /// </summary>
  140. internal static string GetYooStandaloneMacCacheRoot()
  141. {
  142. if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
  143. return Application.persistentDataPath;
  144. else
  145. return PathUtility.Combine(Application.persistentDataPath, Setting.DefaultYooFolderName);
  146. }
  147. /// <summary>
  148. /// 获取YOO的移动平台缓存文件根目录
  149. /// </summary>
  150. internal static string GetYooMobileCacheRoot()
  151. {
  152. if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
  153. return Application.persistentDataPath;
  154. else
  155. return PathUtility.Combine(Application.persistentDataPath, Setting.DefaultYooFolderName);
  156. }
  157. /// <summary>
  158. /// 获取YOO默认的缓存文件根目录
  159. /// </summary>
  160. internal static string GetYooDefaultCacheRoot()
  161. {
  162. #if UNITY_EDITOR
  163. return GetYooEditorCacheRoot();
  164. #elif UNITY_STANDALONE_WIN
  165. return GetYooStandaloneWinCacheRoot();
  166. #elif UNITY_STANDALONE_LINUX
  167. return GetYooStandaloneLinuxCacheRoot();
  168. #elif UNITY_STANDALONE_OSX
  169. return GetYooStandaloneMacCacheRoot();
  170. #else
  171. return GetYooMobileCacheRoot();
  172. #endif
  173. }
  174. /// <summary>
  175. /// 获取YOO默认的内置文件根目录
  176. /// </summary>
  177. internal static string GetYooDefaultBuildinRoot()
  178. {
  179. if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
  180. return Application.streamingAssetsPath;
  181. else
  182. return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
  183. }
  184. #endregion
  185. }
  186. }