PathHelper.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #if !COMBAT_SERVER
  2. using System.IO;
  3. using UnityEngine;
  4. namespace Fort23.Core
  5. {
  6. public static class PathHelper
  7. {
  8. /// <summary>
  9. ///应用程序外部资源路径存放路径(热更新资源路径)
  10. /// </summary>
  11. public static string AppHotfixResPath
  12. {
  13. get
  14. {
  15. if (!Directory.Exists($"{Application.persistentDataPath}/{Application.identifier}/"))
  16. {
  17. Debug.Log("创建目录:" + $"{Application.persistentDataPath}/{Application.identifier}/");
  18. Directory.CreateDirectory($"{Application.persistentDataPath}/{Application.identifier}/");
  19. }
  20. return $"{Application.persistentDataPath}/{Application.identifier}/";
  21. }
  22. }
  23. /// <summary>
  24. /// 应用程序内部资源路径存放路径
  25. /// </summary>
  26. public static string AppResPath
  27. {
  28. get
  29. {
  30. #if UNITY_EDITOR
  31. return Application.streamingAssetsPath;
  32. #elif UNITY_ANDROID
  33. return Application.streamingAssetsPath;
  34. #elif UNITY_IOS
  35. return Application.streamingAssetsPath;
  36. #else
  37. return Application.streamingAssetsPath;
  38. #endif
  39. }
  40. }
  41. /// <summary>
  42. /// 应用程序内部资源路径存放路径(www/webrequest专用)
  43. /// </summary>
  44. public static string AppResPath4Web
  45. {
  46. get
  47. {
  48. #if UNITY_IOS || UNITY_STANDALONE_OSX
  49. return $"file://{Application.streamingAssetsPath}";
  50. #else
  51. return Application.streamingAssetsPath;
  52. #endif
  53. }
  54. }
  55. public static string GetWebRequestPath(string resourceName)
  56. {
  57. string p = GetResPath(resourceName);
  58. // webRequest要加file://
  59. if (!p.Contains("://"))
  60. {
  61. p = "file://" + p;
  62. }
  63. return p;
  64. }
  65. /// <summary>
  66. /// 先从热更路径读取(表示已经热更过),在从内部路径读取(Application.streamingAssetsPath不能用File.Exists判断,无效)
  67. /// </summary>
  68. /// <param name="resourceName"></param>
  69. /// <returns></returns>
  70. private 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. }
  80. }
  81. #endif