三国卡牌客户端基础资源仓库
yyl
2026-05-15 2574cb0172165d6940d8f929a7477ed554493f49
yooasset资源目录更改
3个文件已修改
52 ■■■■ 已修改文件
Assets/Launch/Config/UrlRemoteServices.cs 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Launch/Launch.cs 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Launch/Manager/YooAssetInitializer.cs 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Launch/Config/UrlRemoteServices.cs
@@ -6,6 +6,12 @@
/// 通用的基于 URL 的远程资源服务。
/// 用于非 WebGL 正式包的 HostPlayMode,从版本服务器返回的 resource_url 构建。
/// </summary>
/// <remarks>
/// CDN 目录结构:{baseUrl}/{packageName}/{fileName}
/// 通过在构造时传入 packageName,将包名子路径固化到 _mainUrl/_fallbackUrl 中,
/// GetRemoteMainURL(fileName) 无需感知包名,接口契约不变。
/// 不传 packageName 时行为与旧版完全一致(向下兼容扁平化结构)。
/// </remarks>
public class UrlRemoteServices : IRemoteServices
{
    private readonly string _mainUrl;
@@ -16,12 +22,27 @@
    private static int _loggedUrlCount;
#endif
    public UrlRemoteServices(string baseUrl) : this(baseUrl, baseUrl) { }
    /// <summary>扁平化结构(向下兼容):{baseUrl}/{fileName}</summary>
    public UrlRemoteServices(string baseUrl) : this(baseUrl, baseUrl, null) { }
    public UrlRemoteServices(string mainUrl, string fallbackUrl)
    /// <summary>扁平化结构带备用 CDN(向下兼容):{mainUrl}/{fileName}</summary>
    public UrlRemoteServices(string mainUrl, string fallbackUrl) : this(mainUrl, fallbackUrl, null) { }
    /// <summary>
    /// 按包分目录结构:{mainUrl}/{packageName}/{fileName}
    /// packageName 为 null 时退化为扁平化结构。
    /// </summary>
    public UrlRemoteServices(string mainUrl, string fallbackUrl, string packageName)
    {
        _mainUrl = mainUrl.TrimEnd('/');
        _fallbackUrl = fallbackUrl.TrimEnd('/');
        string main = mainUrl.TrimEnd('/');
        string fallback = fallbackUrl.TrimEnd('/');
        if (!string.IsNullOrEmpty(packageName))
        {
            main = $"{main}/{packageName}";
            fallback = $"{fallback}/{packageName}";
        }
        _mainUrl = main;
        _fallbackUrl = fallback;
    }
    public string GetRemoteMainURL(string fileName)
Assets/Launch/Launch.cs
@@ -105,6 +105,7 @@
        try
        {
            YooAsset.IRemoteServices remoteServices = null;
            string remoteCdnBaseUrl = null;
#if UNITY_EDITOR && (UNITY_WEBGL || UNITY_ANDROID || UNITY_IOS)
            // Editor + 移动/WebGL 构建目标:YooAsset 不支持在这些平台 Editor 内读取 Buildin bundle 文件
            // 强制使用 EditorSimulateMode(不走真实文件系统)
@@ -140,9 +141,11 @@
            // 否则回退到 WebGLRemoteConfig(Editor 模拟或无版本服务器场景)。
            string webCdnUrl = VersionConfigEx.config?.cdnUrl;
            remoteServices = !string.IsNullOrEmpty(webCdnUrl)
                ? new UrlRemoteServices(webCdnUrl + "/" + Application.platform.ToString().ToLower())
                ? null
                : WebGLRemoteConfig.CreateRemoteServices();
            Debug.Log($"[Launch] WebGL remoteServices url={(!string.IsNullOrEmpty(webCdnUrl) ? webCdnUrl : WebGLRemoteConfig.ActiveServerURL)}");
            if (!string.IsNullOrEmpty(webCdnUrl))
                remoteCdnBaseUrl = webCdnUrl + "/" + Application.platform.ToString().ToLower();
            Debug.Log($"[Launch] WebGL remoteCdnBaseUrl={remoteCdnBaseUrl ?? WebGLRemoteConfig.ActiveServerURL}");
#else
            // 非 WebGL 正式包:
            // 先读 VersionConfigEx(Resources.Load,不依赖 YooAsset),
@@ -154,7 +157,7 @@
            if (!string.IsNullOrEmpty(cdnUrl))
            {
                playMode = EPlayMode.HostPlayMode;
                remoteServices = new UrlRemoteServices(cdnUrl + "/" + Application.platform.ToString().ToLower());
                remoteCdnBaseUrl = cdnUrl + "/" + Application.platform.ToString().ToLower();
                Debug.Log($"[Launch] cdnUrl={cdnUrl}, using HostPlayMode");
            }
            else
@@ -165,7 +168,7 @@
#endif
            Debug.Log($"[Launch] Initializing YooAsset early with PlayMode={playMode}");
            await YooAssetInitializer.Instance.InitializeAsync(playMode, remoteServices);
            await YooAssetInitializer.Instance.InitializeAsync(playMode, remoteServices, remoteCdnBaseUrl);
#if UNITY_WEBGL
            await VersionConfigEx.Get();
Assets/Launch/Manager/YooAssetInitializer.cs
@@ -49,6 +49,7 @@
    private EPlayMode _playMode;
    private IRemoteServices _remoteServices;
    private string _remoteCdnBaseUrl;
    private ResourcePackage _defaultPackage;
    private ResourcePackage _prefabPackage;
@@ -140,7 +141,7 @@
    /// <param name="remoteServices">CDN 远程服务地址配置(HostPlayMode 必需)</param>
    /// <param name="packageNames">要初始化的包名列表,null 使用 LAUNCH_PACKAGES</param>
    public async UniTask InitializeAsync(EPlayMode playMode = EPlayMode.HostPlayMode,
        IRemoteServices remoteServices = null, string[] packageNames = null)
        IRemoteServices remoteServices = null, string remoteCdnBaseUrl = null, string[] packageNames = null)
    {
        if (State != InitState.Uninitialized)
        {
@@ -151,6 +152,7 @@
        State = InitState.Initializing;
        _playMode = playMode;
        _remoteServices = remoteServices;
        _remoteCdnBaseUrl = remoteCdnBaseUrl;
        var names = packageNames ?? LAUNCH_PACKAGES;
        int successCount = 0;
@@ -620,13 +622,18 @@
            case EPlayMode.HostPlayMode:
            {
                bool hasBuildin = HasBuildinPackage(packageName);
                // 有 remoteCdnBaseUrl 时为每个包单独创建带子路径的 RemoteServices
                // 例:{cdnBase}/android/{packageName}/{fileName}
                var effectiveRemote = !string.IsNullOrEmpty(_remoteCdnBaseUrl)
                    ? new UrlRemoteServices(_remoteCdnBaseUrl, _remoteCdnBaseUrl, packageName)
                    : remoteServices;
                return new HostPlayModeParameters
                {
                    BuildinFileSystemParameters = hasBuildin
                        ? FileSystemParameters.CreateDefaultBuildinFileSystemParameters()
                        : null,
                    CacheFileSystemParameters = FileSystemParameters
                        .CreateDefaultCacheFileSystemParameters(remoteServices)
                        .CreateDefaultCacheFileSystemParameters(effectiveRemote)
                };
            }
            case EPlayMode.OfflinePlayMode:
@@ -680,6 +687,7 @@
        _defaultPackage = null;
        _packages.Clear();
        _remoteServices = null;
        _remoteCdnBaseUrl = null;
        LastError = null;
        State = InitState.Uninitialized;
    }