| | |
| | | // 特殊表格
|
| | | "InitialFunctionConfig",
|
| | | "PriorLanguageConfig",
|
| | |
|
| | | // 正常读取小于5ms的表 使用lazyload
|
| | | "AppointItemConfig",
|
| | | "AudioConfig",
|
| | | "ChatBubbleBoxConfig",
|
| | | "ChestsConfig",
|
| | | "CTGSelectItemConfig",
|
| | | "DailyLivenessRewardConfig",
|
| | | "DailyQuestConfig",
|
| | | "DailyQuestOpenTimeConfig",
|
| | | "DienstgradConfig",
|
| | | "DirtyNameConfig",
|
| | | "EffectConfig",
|
| | | "EmojiPackConfig",
|
| | | "EquipPlaceMapConfig",
|
| | | "FamilyConfig",
|
| | | "FamilyEmblemConfig",
|
| | | "FirstGoldConfig",
|
| | | "FrameAnimationConfig",
|
| | | "FuncConfigConfig",
|
| | | "FuncOpenLVConfig",
|
| | | "FunctionTeamSetConfig",
|
| | | "GetItemWaysConfig",
|
| | | "GmCmdConfig",
|
| | | "GuideConfig",
|
| | | "HeroAwakeConfig",
|
| | | "HeroBreakConfig",
|
| | | "HeroConfig",
|
| | | "HeroFetterConfig",
|
| | | "HeroQualityAwakeConfig",
|
| | | "HeroQualityBreakConfig",
|
| | | "HeroQualityConfig",
|
| | | "HeroSkinConfig",
|
| | | "HeroTalentConfig",
|
| | | "IconConfig",
|
| | | "ItemConfig",
|
| | | "KickOutReasonConfig",
|
| | | "LanguageConfig",
|
| | | "MailConfig",
|
| | | "PlayerFaceConfig",
|
| | | "PlayerFacePicConfig",
|
| | | "PlayerPropertyConfig",
|
| | | "priorbundleConfig",
|
| | | "RealmConfig",
|
| | | "RealmLVUPTaskConfig",
|
| | | "RichTextMsgReplaceConfig",
|
| | | "RuleConfig",
|
| | | "SkillConfig",
|
| | | "TaskConfig",
|
| | | "TreasureCntAwardConfig",
|
| | | };
|
| | |
|
| | | [MenuItem("Tools/手动刷新")]
|
| | |
| | | {
|
| | | // 获取所有配置类
|
| | | List<string> configClasses = GetAllConfigClasses();
|
| | | |
| | |
|
| | | if (System.IO.File.Exists(Path.Combine(Application.dataPath, "fastConfig.txt")))
|
| | | {
|
| | | // 如果存在 fastConfig.txt 文件,读取其中的配置类
|
| | | string[] fastConfigs = System.IO.File.ReadAllLines(Path.Combine(Application.dataPath, "fastConfig.txt"));
|
| | | ExcludeClassList.AddRange(fastConfigs);
|
| | | }
|
| | |
|
| | | configClasses = new List<string>(configClasses.Where(config => !ExcludeClassList.Contains(config)));
|
| | |
|
| | | // 生成配置管理器代码
|
| | |
| | | private static string GenerateFullConfigManagerCode(List<string> configClasses)
|
| | | {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | |
| | | // 添加命名空间引用
|
| | |
|
| | | // 头部命名空间
|
| | | sb.AppendLine("using System;");
|
| | | sb.AppendLine("using System.Collections.Generic;");
|
| | | sb.AppendLine("using UnityEngine;");
|
| | |
| | | sb.AppendLine();
|
| | | sb.AppendLine("public class ConfigManager : ManagerBase<ConfigManager>");
|
| | | sb.AppendLine("{");
|
| | | |
| | | // 添加属性和字段
|
| | | sb.AppendLine(" public bool isLoadFinished");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" get;");
|
| | |
| | | sb.AppendLine();
|
| | | sb.AppendLine(" private float loadingProgress = 0f;");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加初始化方法
|
| | | sb.AppendLine(" public override void Init()");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" base.Init();");
|
| | | sb.AppendLine(" InitConfigs();");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加配置初始化方法
|
| | | sb.AppendLine(" public virtual async UniTask InitConfigs()");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" // 加载配置文件");
|
| | | sb.AppendLine(" await LoadConfigs();");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加LoadConfigs方法
|
| | | sb.AppendLine(" protected async UniTask LoadConfigs()");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" loadingProgress = 0f;");
|
| | | sb.AppendLine(" isLoadFinished = false;");
|
| | | sb.AppendLine();
|
| | | sb.AppendLine(" // 加载配置文件");
|
| | | |
| | | // 如果有配置类,添加进度跟踪代码
|
| | | if (configClasses.Count > 0)
|
| | | sb.AppendLine($" int totalConfigs = {configClasses.Count};");
|
| | | sb.AppendLine(" List<Type> configTypes = new List<Type>() {");
|
| | | for (int i = 0; i < configClasses.Count; i++)
|
| | | {
|
| | | sb.AppendLine($" int totalConfigs = {configClasses.Count};");
|
| | | |
| | | // 使用数组和循环加载配置
|
| | | sb.AppendLine(" Type[] configTypes = new Type[] {");
|
| | | for (int i = 0; i < configClasses.Count; i++)
|
| | | {
|
| | | sb.Append($" typeof({configClasses[i]})");
|
| | | sb.AppendLine(i < configClasses.Count - 1 ? "," : "");
|
| | | }
|
| | | sb.AppendLine(" };");
|
| | | sb.AppendLine();
|
| | | sb.AppendLine("#if UNITY_EDITOR");
|
| | | sb.AppendLine(" List<string> fastName = new List<string>();");
|
| | | sb.AppendLine("#endif");
|
| | |
|
| | |
|
| | | sb.AppendLine(" // 逐个加载配置并更新进度");
|
| | | sb.AppendLine(" for (int i = 0; i < configTypes.Length; i++)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" var sw = System.Diagnostics.Stopwatch.StartNew();");
|
| | | sb.AppendLine(" LoadConfigByType(configTypes[i]);");
|
| | | sb.AppendLine(" sw.Stop();");
|
| | | sb.AppendLine("#if UNITY_EDITOR");
|
| | | sb.AppendLine(" if (sw.ElapsedMilliseconds >= 100)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" Debug.LogError($\"加载配置 {configTypes[i].Name} 耗时较长: {sw.ElapsedMilliseconds} ms\");");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" else if (sw.ElapsedMilliseconds <= 5)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" fastName.Add(configTypes[i].Name);");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" Debug.Log($\"加载配置: {configTypes[i].Name} 用时: {sw.ElapsedMilliseconds} ms\");");
|
| | | sb.AppendLine("#endif");
|
| | | sb.AppendLine(" loadingProgress = (float)(i + 1) / totalConfigs;");
|
| | | sb.AppendLine(" }");
|
| | | sb.Append($" typeof({configClasses[i]})");
|
| | | sb.AppendLine(i < configClasses.Count - 1 ? "," : "");
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogError("没有找到配置类 : " + configClasses.Count);
|
| | | }
|
| | | |
| | | sb.AppendLine(" };");
|
| | | sb.AppendLine();
|
| | | sb.AppendLine("#if UNITY_EDITOR");
|
| | | sb.AppendLine(" HashSet<Type> configHashSet = new HashSet<Type>();");
|
| | | sb.AppendLine(" if (System.IO.File.Exists(Application.dataPath + \"/fastConfig.txt\"))");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" string[] strConfgsArr = System.IO.File.ReadAllLines(Application.dataPath + \"/fastConfig.txt\");");
|
| | | sb.AppendLine(" foreach (string str in strConfgsArr)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" Type tpy = Type.GetType(str);");
|
| | | sb.AppendLine(" configHashSet.Add(tpy);");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" // 编辑器下加入 评估加载时常");
|
| | | sb.AppendLine(" configTypes.AddRange(configHashSet);");
|
| | | sb.AppendLine(" List<string> fastName = new List<string>();");
|
| | | sb.AppendLine("#endif");
|
| | | sb.AppendLine(" // 逐个加载配置并更新进度");
|
| | | sb.AppendLine(" for (int i = 0; i < configTypes.Count; i++)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" var sw = System.Diagnostics.Stopwatch.StartNew();");
|
| | | sb.AppendLine(" LoadConfigByType(configTypes[i]);");
|
| | | sb.AppendLine(" sw.Stop();");
|
| | | sb.AppendLine("#if UNITY_EDITOR");
|
| | | sb.AppendLine(" if (sw.ElapsedMilliseconds >= 100)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" Debug.LogError($\"加载配置 {configTypes[i].Name} 耗时较长: {sw.ElapsedMilliseconds} ms\");");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" else if (sw.ElapsedMilliseconds <= 5)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" fastName.Add(configTypes[i].Name);");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" Debug.Log($\"加载配置: {configTypes[i].Name} 用时: {sw.ElapsedMilliseconds} ms\");");
|
| | | sb.AppendLine("#endif");
|
| | | sb.AppendLine(" loadingProgress = (float)(i + 1) / totalConfigs;");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine("#if UNITY_EDITOR");
|
| | | sb.AppendLine(" System.IO.File.WriteAllText(Application.dataPath + \"/fastConfig.txt\", string.Join(\"\\n\", fastName));");
|
| | | sb.AppendLine();
|
| | | sb.AppendLine(" //加载完后卸载");
|
| | | sb.AppendLine(" foreach (var configType in configTypes)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" var methodInfo = configType.GetMethod(\"ForceRelease\", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);");
|
| | | sb.AppendLine(" if (methodInfo != null)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" methodInfo.Invoke(null, null);");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine("#endif");
|
| | | sb.AppendLine();
|
| | | sb.AppendLine(" // 加载完成后设置isLoadFinished为true");
|
| | |
| | | sb.AppendLine(" isLoadFinished = true;");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加LoadConfigByType方法
|
| | | sb.AppendLine(" public void LoadConfigByType(Type configType)");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" string configName = configType.Name;");
|
| | |
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加泛型LoadConfig方法
|
| | | sb.AppendLine(" private async UniTask LoadConfig<T>() where T : class");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" string configName = typeof(T).Name;");
|
| | |
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加GetLoadingProgress方法
|
| | | sb.AppendLine(" public float GetLoadingProgress()");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" return loadingProgress;");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加ClearConfigDictionary方法
|
| | | sb.AppendLine(" private void ClearConfigDictionary<T>() where T : class");
|
| | | sb.AppendLine(" {");
|
| | | sb.AppendLine(" // 重置 T 初始化状态");
|
| | |
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine(" }");
|
| | | sb.AppendLine();
|
| | | |
| | | // 添加Release方法
|
| | | sb.AppendLine(" public override void Release()");
|
| | | sb.AppendLine(" {");
|
| | | |
| | | if (configClasses.Count > 0)
|
| | | foreach (string className in configClasses)
|
| | | {
|
| | | foreach (string className in configClasses)
|
| | | {
|
| | | // 清空字典
|
| | | sb.AppendLine($" // 清空 {className} 字典");
|
| | | sb.AppendLine($" ClearConfigDictionary<{className}>();");
|
| | | }
|
| | | sb.AppendLine($" // 清空 {className} 字典");
|
| | | sb.AppendLine($" ClearConfigDictionary<{className}>();");
|
| | | }
|
| | | else
|
| | | {
|
| | | sb.AppendLine(" // 没有找到配置类");
|
| | | }
|
| | | |
| | | sb.AppendLine(" }");
|
| | | |
| | | // 结束类定义
|
| | | sb.AppendLine("}");
|
| | | |
| | |
|
| | | return sb.ToString();
|
| | | }
|
| | | } |