// ============================================================================ // RemoteServicesImpl.cs — IRemoteServices 实现 // 配合平台抽象层提供 CDN 地址,支持多平台 CDN 路由 // ============================================================================ using YooAsset; namespace ProjSG.Resource { /// /// YooAsset 远程服务实现。 /// 提供主 CDN 和备用 CDN 的资源下载地址拼接。 /// public class RemoteServicesImpl : IRemoteServices { private readonly string _mainUrl; private readonly string _fallbackUrl; /// /// 创建远程服务配置。 /// /// 主 CDN 根地址(如 https://cdn.example.com/bundles/) /// 备用 CDN 根地址 public RemoteServicesImpl(string mainUrl, string fallbackUrl) { _mainUrl = mainUrl; _fallbackUrl = fallbackUrl; } /// /// 获取主 CDN 下载地址。 /// public string GetRemoteMainURL(string fileName) { return $"{_mainUrl}/{fileName}"; } /// /// 获取备用 CDN 下载地址。 /// public string GetRemoteFallbackURL(string fileName) { return $"{_fallbackUrl}/{fileName}"; } /// /// 根据当前平台创建 RemoteServicesImpl。 /// 通过 IPlatformService + PlatformFactory 自动路由到对应平台的 CDN。 /// /// 基础 CDN 地址(如 https://cdn.example.com) /// 备用 CDN 地址(可选,默认同 baseCdnUrl) /// 平台对应的 RemoteServicesImpl 实例 // public static RemoteServicesImpl CreateForCurrentPlatform(string baseCdnUrl, string fallbackCdnUrl = null) // { // fallbackCdnUrl = fallbackCdnUrl ?? baseCdnUrl; // var platform = PlatformFactory.GetCurrent(); // var platformType = platform.GetPlatformType(); // // 按平台类型路由子路径 // string platformPath = GetPlatformCdnPath(platformType); // string mainUrl = $"{baseCdnUrl}/{platformPath}"; // string fallbackUrl = $"{fallbackCdnUrl}/{platformPath}"; // UnityEngine.Debug.Log($"[RemoteServicesImpl] Platform={platformType}, CDN={mainUrl}"); // return new RemoteServicesImpl(mainUrl, fallbackUrl); // } /// /// 获取平台对应的 CDN 子路径。 /// private static string GetPlatformCdnPath(PlatformType platformType) { switch (platformType) { case PlatformType.WeChat: return "wechat/bundles"; case PlatformType.Douyin: return "douyin/bundles"; case PlatformType.Vivo: return "vivo/bundles"; // OPPO / Kuaishou 等可在此扩展 case PlatformType.Standalone: default: return "standalone/bundles"; } } } }