yyl
2026-02-11 3f2cd27c5dfb3b450245bf1a37fc1b3414031c7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// ============================================================================
// YooAssetPackageConfig.cs — YooAsset 多 Package 架构配置
// 定义 Package 名称常量和资源目录→Package 路由表
// ============================================================================
//
// 在 YooAsset Editor (YooAsset → AssetBundle Collector) 中配置:
// 每个 Package 对应一个独立的构建产物,可独立下载和更新。
//
// ┌───────────────┬─────────────────────────────────────────┬──────────────┐
// │ Package       │ 收集路径 (CollectPath)                    │ 部署方式      │
// ├───────────────┼─────────────────────────────────────────┼──────────────┤
// │ UI            │ Assets/ResourcesOut/UI                  │ Remote       │
// │               │ Assets/ResourcesOut/UIComp              │              │
// │               │ Assets/ResourcesOut/Sprite              │              │
// │               │ Assets/ResourcesOut/Texture             │              │
// │               │ Assets/ResourcesOut/Font                │              │
// ├───────────────┼─────────────────────────────────────────┼──────────────┤
// │ Prefab        │ Assets/ResourcesOut/BuiltIn             │ Remote       │
// │               │ Assets/ResourcesOut/Shader              │              │
// │               │ Assets/ResourcesOut/Materials           │              │
// │               │ Assets/ResourcesOut/ScriptableObject    │              │
// │               │ Assets/ResourcesOut/Scenes              │              │
// │               │ Assets/ResourcesOut/Config              │              │
// ├───────────────┼─────────────────────────────────────────┼──────────────┤
// │ UIEffect      │ Assets/ResourcesOut/UIEffect (已有)      │ Remote       │
// ├───────────────┼─────────────────────────────────────────┼──────────────┤
// │ Dll           │ HybridCLR 热更 DLL                       │ Remote       │
// ├───────────────┼─────────────────────────────────────────┼──────────────┤
// │ Battle        │ Assets/ResourcesOut/Hero                │ Remote       │
// │               │ Assets/ResourcesOut/Battle              │              │
// ├───────────────┼─────────────────────────────────────────┼──────────────┤
// │ Audio         │ Assets/ResourcesOut/Audio               │ Remote       │
// └───────────────┴─────────────────────────────────────────┴──────────────┘
//
// ============================================================================
 
using System.Collections.Generic;
 
namespace ProjSG.Resource
{
    /// <summary>
    /// YooAsset Package 名称常量。
    /// 必须与 AssetBundleCollectorSetting.asset 中的 PackageName 一致。
    /// </summary>
    public static class YooAssetPackageConfig
    {
        // ====================================================================
        // Package 名称(与 Collector 完全一致)
        // ====================================================================
 
        /// <summary>UI 资源包:UI 窗口、UIComp、Sprite、Texture、Font</summary>
        public const string UI = "UI";
 
        /// <summary>通用预制体包:BuiltIn、Shader、Materials、ScriptableObject、Scenes、Config</summary>
        public const string Prefab = "Prefab";
 
        /// <summary>UI 特效包:UIEffect 目录</summary>
        public const string UIEffect = "UIEffect";
 
        /// <summary>HybridCLR 热更 DLL 包</summary>
        public const string Dll = "Dll";
 
        /// <summary>战斗资源包:Hero Spine、Battle Prefabs</summary>
        public const string Battle = "Battle";
 
        /// <summary>音频资源包:Audio 目录</summary>
        public const string Audio = "Audio";
 
        /// <summary>
        /// 主包名 — 在 YooAssetService/YooAssetInitializer 中作为 DefaultPackage。
        /// 选择 Prefab 包,因为它包含 BuiltIn/Shader/Materials 等启动必需资源。
        /// </summary>
        public const string DefaultPackage = Prefab;
 
        /// <summary>
        /// 所有需要初始化的 Package(不含 Dll,Dll 包由热更流程单独管理)。
        /// </summary>
        public static readonly string[] AllPackages = new[]
        {
            Prefab,     // 先初始化默认包
            UI,
            UIEffect,
            Battle,
            Audio,
        };
 
        // ====================================================================
        // 资源目录 → Package 路由表
        // ====================================================================
 
        /// <summary>
        /// 资源目录前缀到 Package 名称的映射。
        /// key 是 ResourcesOut 下的一级目录名(小写),value 是 Package 名称。
        /// </summary>
        private static readonly Dictionary<string, string> _directoryToPackage = new Dictionary<string, string>
        {
            // UI Package
            { "ui", UI },
            { "uicomp", UI },
            { "sprite", UI },
            { "texture", UI },
            { "font", UI },
 
            // Prefab Package (default — BuiltIn, Shader, Materials, etc.)
            { "builtin", Prefab },
            { "shader", Prefab },
            { "materials", Prefab },
            { "graphic", Prefab },        // 旧路径兼容 "Graphic/Shader", "Graphic/Material"
            { "scriptableobject", Prefab },
            { "scenes", Prefab },
            { "config", Prefab },
            { "prefab", Prefab },
 
            // UIEffect Package
            { "uieffect", UIEffect },
            { "effect", UIEffect },
 
            // Battle Package
            { "hero", Battle },
            { "battle", Battle },
 
            // Audio Package
            { "audio", Audio },
        };
 
        /// <summary>
        /// 根据完整资源路径确定应使用的 Package 名称。
        /// 例如 "Assets/ResourcesOut/UI/LoginWin.prefab" → "UI"
        /// 例如 "Assets/ResourcesOut/BuiltIn/Font/MainFont.ttf" → "Prefab"
        /// </summary>
        /// <param name="location">资源路径(完整路径或相对路径)</param>
        /// <returns>Package 名称,匹配不到返回 DefaultPackage</returns>
        public static string GetPackageForLocation(string location)
        {
            if (string.IsNullOrEmpty(location))
                return DefaultPackage;
 
            // 去掉 "Assets/ResourcesOut/" 前缀
            string relativePath = location;
            const string PREFIX = "Assets/ResourcesOut/";
            if (relativePath.StartsWith(PREFIX))
            {
                relativePath = relativePath.Substring(PREFIX.Length);
            }
 
            // 取一级目录名
            int slashIndex = relativePath.IndexOf('/');
            string topDir = slashIndex >= 0
                ? relativePath.Substring(0, slashIndex)
                : relativePath;
 
            if (_directoryToPackage.TryGetValue(topDir.ToLower(), out string packageName))
            {
                return packageName;
            }
 
            return DefaultPackage;
        }
    }
 
    /// <summary>
    /// YooAsset 资源标签常量。
    /// 用于细粒度资源分组和按需下载。
    /// </summary>
    public static class YooAssetTagConfig
    {
        // 战斗相关
        public const string BattleSpine = "tag_battle_spine";
        public const string BattleEffect = "tag_battle_effect";
        public const string BattleSound = "tag_battle_sound";
        public const string BattleMap = "tag_battle_map";
 
        // UI 相关
        public const string UIMain = "tag_ui_main";
        public const string UIShop = "tag_ui_shop";
        public const string UIBattle = "tag_ui_battle";
        public const string UIHero = "tag_ui_hero";
 
        // 通用
        public const string Shader = "tag_shader";
        public const string Font = "tag_font";
        public const string Material = "tag_material";
    }
}