From ae454b72dcdf5d2a5a247b3b910dfe28d101ae72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 13 Aug 2024 10:54:29 +0800 Subject: [PATCH] update extension sample --- .../WechatFileSystem/WechatFileSystem.cs | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs index 3ae11d0..9982cb7 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/WechatFileSystem/WechatFileSystem.cs @@ -21,6 +21,36 @@ public static class WechatFileSystemCreater /// internal class WechatFileSystem : IFileSystem { + private class WebRemoteServices : IRemoteServices + { + private readonly string _webPackageRoot; + protected readonly Dictionary _mapping = new Dictionary(10000); + + public WebRemoteServices(string buildinPackRoot) + { + _webPackageRoot = buildinPackRoot; + } + string IRemoteServices.GetRemoteMainURL(string fileName) + { + return GetFileLoadURL(fileName); + } + string IRemoteServices.GetRemoteFallbackURL(string fileName) + { + return GetFileLoadURL(fileName); + } + + private string GetFileLoadURL(string fileName) + { + if (_mapping.TryGetValue(fileName, out string url) == false) + { + string filePath = PathUtility.Combine(_webPackageRoot, fileName); + url = DownloadSystemHelper.ConvertToWWWPath(filePath); + _mapping.Add(fileName, url); + } + return url; + } + } + private readonly Dictionary _wxFilePaths = new Dictionary(10000); private WXFileSystemManager _wxFileSystemMgr; private string _wxFileCacheRoot = string.Empty; @@ -52,12 +82,12 @@ internal class WechatFileSystem : IFileSystem } } -#region 自定义参数 + #region 自定义参数 /// /// 自定义参数:远程服务接口 /// public IRemoteServices RemoteServices { private set; get; } = null; -#endregion + #endregion public WechatFileSystem() @@ -129,6 +159,13 @@ internal class WechatFileSystem : IFileSystem { PackageName = packageName; + // 注意:CDN服务未启用的情况下,使用微信WEB服务器 + if (RemoteServices == null) + { + string webRoot = PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName, packageName); + RemoteServices = new WebRemoteServices(webRoot); + } + _wxFileSystemMgr = WX.GetFileSystemManager(); _wxFileCacheRoot = WX.env.USER_DATA_PATH; //注意:如果有子目录,请修改此处! } @@ -171,7 +208,7 @@ internal class WechatFileSystem : IFileSystem throw new System.NotImplementedException(); } -#region 内部方法 + #region 内部方法 private string GetWXFileLoadPath(PackageBundle bundle) { if (_wxFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false) @@ -181,6 +218,6 @@ internal class WechatFileSystem : IFileSystem } return filePath; } -#endregion + #endregion } #endif \ No newline at end of file