FileDefine.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using XGame.Framework.Utils;
  2. using System.IO;
  3. namespace XGame.Framework.Define
  4. {
  5. /// <summary>
  6. /// 框架用的 非AB文件 路径的静态定义
  7. ///
  8. /// * 注意:
  9. /// 1、请写相对路径
  10. /// 2、相对于UpdatePath、WorkPath的路径
  11. /// </summary>
  12. public static class FileDefine
  13. {
  14. public const string ObsoleteAssetsPrefix = "ObsoleteAssets";
  15. public static readonly PathWrapper XGameDirectory = new("XGame");
  16. }
  17. /// <summary>
  18. /// XGame用的文件路径
  19. /// </summary>
  20. public struct PathWrapper
  21. {
  22. public string RelativePath { get; private set; }
  23. public PathWrapper(string relativePath)
  24. {
  25. RelativePath = relativePath;
  26. }
  27. /// <summary>
  28. /// AssetBundle文件(UpdateAssets ----no exist--->StreamAssets)
  29. /// </summary>
  30. public string AssetBundlePath => FileUtils.GetAssetBundlePath(RelativePath).Replace("\\", "/");
  31. /// <summary>
  32. /// 游戏文件路径(UpdateAssets ----no exist--->StreamAssets)
  33. /// </summary>
  34. public string FilePath => FileUtils.GetFilePath(RelativePath).Replace("\\", "/");
  35. /// <summary>
  36. /// 游戏文件URL(UpdateAssets ----no exist--->StreamAssets)
  37. /// </summary>
  38. public string UrlPath => FileUtils.GetFileUrl(RelativePath).Replace("\\", "/");
  39. /// <summary>
  40. /// 热更路径(UpdateAssets ----> no exist)(不会找包内路径,不存在就是不存在了)
  41. /// </summary>
  42. public string UpdatePath => Path.Combine(PathDefine.UpdatePath, RelativePath).Replace("\\", "/");
  43. /// <summary>
  44. /// 项目专用的沙盒目录(SandboxAssets ----> no exist)(不会找包内路径,不存在就是不存在了)
  45. /// </summary>
  46. public string SandboxPath => Path.Combine(PathDefine.SandboxPath, RelativePath).Replace("\\", "/");
  47. /// <summary>
  48. /// 包内StreamingAssets路径, 只读
  49. /// </summary>
  50. public string StreamingPath => Path.Combine(PathDefine.WorkPath, RelativePath).Replace("\\", "/");
  51. /// <summary>
  52. /// 沙盒根目录(Android下, Files目录, 项目禁止使用, 需要读写权限的目录请使用SandboxPath)
  53. /// </summary>
  54. internal string PersistentPath => Path.Combine(PathDefine.PersistentDataPath, RelativePath).Replace("\\", "/");
  55. /// <summary>
  56. /// 默认为FilePath!!
  57. /// </summary>
  58. /// <param name="wrapper"></param>
  59. public static implicit operator string(PathWrapper wrapper)
  60. {
  61. return wrapper.FilePath;
  62. }
  63. }
  64. }