DefaultWebRemoteFileSystem.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace YooAsset
  6. {
  7. /// <summary>
  8. /// Web文件系统
  9. /// </summary>
  10. internal class DefaultWebRemoteFileSystem : IFileSystem
  11. {
  12. /// <summary>
  13. /// 包裹名称
  14. /// </summary>
  15. public string PackageName { private set; get; }
  16. /// <summary>
  17. /// 文件根目录
  18. /// </summary>
  19. public string FileRoot
  20. {
  21. get
  22. {
  23. return string.Empty;
  24. }
  25. }
  26. /// <summary>
  27. /// 文件数量
  28. /// </summary>
  29. public int FileCount
  30. {
  31. get
  32. {
  33. return 0;
  34. }
  35. }
  36. #region 自定义参数
  37. /// <summary>
  38. /// 禁用Unity的网络缓存
  39. /// </summary>
  40. public bool DisableUnityWebCache { private set; get; } = false;
  41. /// <summary>
  42. /// 自定义参数:跨域下载服务接口
  43. /// </summary>
  44. public IRemoteServices RemoteServices { private set; get; } = null;
  45. /// <summary>
  46. /// 自定义参数:解密方法类
  47. /// </summary>
  48. public IWebDecryptionServices DecryptionServices { private set; get; }
  49. #endregion
  50. public DefaultWebRemoteFileSystem()
  51. {
  52. }
  53. public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
  54. {
  55. var operation = new DWRFSInitializeOperation(this);
  56. return operation;
  57. }
  58. public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
  59. {
  60. var operation = new DWRFSLoadPackageManifestOperation(this, packageVersion, timeout);
  61. return operation;
  62. }
  63. public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
  64. {
  65. var operation = new DWRFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
  66. return operation;
  67. }
  68. public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
  69. {
  70. var operation = new FSClearCacheFilesCompleteOperation();
  71. return operation;
  72. }
  73. public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
  74. {
  75. throw new System.NotImplementedException();
  76. }
  77. public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
  78. {
  79. if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
  80. {
  81. var operation = new DWRFSLoadAssetBundleOperation(this, bundle);
  82. return operation;
  83. }
  84. else
  85. {
  86. string error = $"{nameof(DefaultWebRemoteFileSystem)} not support load bundle type : {bundle.BundleType}";
  87. var operation = new FSLoadBundleCompleteOperation(error);
  88. return operation;
  89. }
  90. }
  91. public virtual void SetParameter(string name, object value)
  92. {
  93. if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
  94. {
  95. DisableUnityWebCache = Convert.ToBoolean(value);
  96. }
  97. else if (name == FileSystemParametersDefine.REMOTE_SERVICES)
  98. {
  99. RemoteServices = (IRemoteServices)value;
  100. }
  101. else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
  102. {
  103. DecryptionServices = (IWebDecryptionServices)value;
  104. }
  105. else
  106. {
  107. YooLogger.Warning($"Invalid parameter : {name}");
  108. }
  109. }
  110. public virtual void OnCreate(string packageName, string packageRoot)
  111. {
  112. PackageName = packageName;
  113. }
  114. public virtual void OnDestroy()
  115. {
  116. }
  117. public virtual bool Belong(PackageBundle bundle)
  118. {
  119. return true;
  120. }
  121. public virtual bool Exists(PackageBundle bundle)
  122. {
  123. return true;
  124. }
  125. public virtual bool NeedDownload(PackageBundle bundle)
  126. {
  127. return false;
  128. }
  129. public virtual bool NeedUnpack(PackageBundle bundle)
  130. {
  131. return false;
  132. }
  133. public virtual bool NeedImport(PackageBundle bundle)
  134. {
  135. return false;
  136. }
  137. public virtual string GetBundleFilePath(PackageBundle bundle)
  138. {
  139. throw new System.NotImplementedException();
  140. }
  141. public virtual byte[] ReadBundleFileData(PackageBundle bundle)
  142. {
  143. throw new System.NotImplementedException();
  144. }
  145. public virtual string ReadBundleFileText(PackageBundle bundle)
  146. {
  147. throw new System.NotImplementedException();
  148. }
  149. #region 内部方法
  150. #endregion
  151. }
  152. }