PathDefine.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. namespace XGame.Framework.Define
  5. {
  6. public static class PathDefine
  7. {
  8. private static readonly string _dataPath = Application.dataPath;
  9. #if UNITY_EDITOR
  10. private static readonly string _streamingAssetsPath = Environment.CurrentDirectory.Replace("\\", "/") + "/ExtAssets/StreamAssets";
  11. #else
  12. private static readonly string _streamingAssetsPath = Application.streamingAssetsPath;
  13. #endif
  14. #if UNITY_EDITOR
  15. private static readonly string _persistentDataPath = Environment.CurrentDirectory.Replace("\\", "/") + "/ExtAssets";
  16. #elif UNITY_STANDALONE
  17. private static readonly string _persistentDataPath = Application.dataPath;
  18. #else
  19. private static readonly string _persistentDataPath = Application.persistentDataPath;
  20. #endif
  21. /// <summary>
  22. /// 热更文件目录
  23. /// </summary>
  24. private static readonly string _updatePath = _persistentDataPath + "/UpdateAssets";
  25. /// <summary>
  26. /// 项目的沙盒目录
  27. /// </summary>
  28. private static readonly string _sandboxPath = _persistentDataPath + "/SandboxAssets";
  29. public static string PersistentDataPath => _persistentDataPath;
  30. public static string WorkPath
  31. {
  32. get
  33. {
  34. return _streamingAssetsPath;
  35. }
  36. }
  37. /// <summary>
  38. /// 热更目录
  39. /// </summary>
  40. public static string UpdatePath
  41. {
  42. get
  43. {
  44. var path = _updatePath;
  45. if (!Directory.Exists(path))
  46. {
  47. try
  48. {
  49. Directory.CreateDirectory(path);
  50. }
  51. catch (Exception ex)
  52. {
  53. Log.Error("PathDefine.UpdatePath - Error creating {0}. Exception={1}", path, ex.Message);
  54. }
  55. }
  56. return path;
  57. }
  58. }
  59. /// <summary>
  60. /// 项目的沙盒目录
  61. /// </summary>
  62. public static string SandboxPath
  63. {
  64. get
  65. {
  66. var path = _sandboxPath;
  67. if (!Directory.Exists(path))
  68. {
  69. try
  70. {
  71. Directory.CreateDirectory(path);
  72. }
  73. catch (Exception ex)
  74. {
  75. Log.Error("PathDefine.SandboxPath - Error creating {0}. Exception={1}", path, ex.Message);
  76. }
  77. }
  78. return path;
  79. }
  80. }
  81. }
  82. }