| | |
| | | private set;
|
| | | }
|
| | |
|
| | | private List<Type> preInitConfig = new List<Type>()
|
| | | {
|
| | | typeof (FuncConfigConfig), |
| | | };
|
| | |
|
| | | private float loadingProgress = 0f;
|
| | |
|
| | | public override void Init()
|
| | | public override async UniTask Init()
|
| | | {
|
| | | base.Init();
|
| | | InitConfigs();
|
| | | await InitConfigs();
|
| | | }
|
| | |
|
| | | public virtual async UniTask InitConfigs()
|
| | |
| | | await LoadConfigs();
|
| | | }
|
| | |
|
| | | public async UniTask PreInit()
|
| | | {
|
| | | List<UniTask> uniTasks = new List<UniTask>();
|
| | | foreach (var type in preInitConfig)
|
| | | {
|
| | | uniTasks.Add(LoadConfigByTypeAsync(type));
|
| | | }
|
| | | await UniTask.WhenAll(uniTasks);
|
| | | }
|
| | |
|
| | | protected async UniTask LoadConfigs()
|
| | | {
|
| | | loadingProgress = 0f;
|
| | | isLoadFinished = false;
|
| | |
|
| | | // 加载配置文件
|
| | | // 加载配置文件
|
| | | // 加载配置文件
|
| | | // 加载配置文件
|
| | | HashSet<Type> configTypes = new HashSet<Type>() {
|
| | | typeof(ActBillboardAwardConfig),
|
| | | typeof(ActHeroAppearArtConfig),
|
| | | typeof(ActHeroAppearConfig),
|
| | | typeof(ActHeroAppearArtConfig),
|
| | | typeof(ActHeroAppearStarConfig),
|
| | | typeof(ActHeroReturnArtConfig),
|
| | | typeof(ActLunhuidianTypeConfig),
|
| | | typeof(ActSignAwardConfig),
|
| | | typeof(ActSignConfig),
|
| | | typeof(ActSignAwardConfig),
|
| | | typeof(ActSpecialSaleConfig),
|
| | | typeof(ActTaskConfig),
|
| | | typeof(ActTaskTempConfig),
|
| | |
| | | typeof(ActTotDayRechargeConfig),
|
| | | typeof(ActTotDayRechargeTempConfig),
|
| | | typeof(ADAwardConfig),
|
| | | typeof(AppointItemConfig),
|
| | | typeof(AudioConfig),
|
| | | typeof(BattleMapConfig),
|
| | | typeof(BeautyConfig),
|
| | | typeof(BeautyQualityLVConfig),
|
| | | typeof(BeautySkinConfig),
|
| | | typeof(ChatBubbleBoxConfig),
|
| | | typeof(ChestsConfig),
|
| | | typeof(ChestsAwardConfig),
|
| | | typeof(CTGConfig),
|
| | | typeof(CTGSelectItemConfig),
|
| | | typeof(DailyLivenessRewardConfig),
|
| | | typeof(DailyTaskConfig),
|
| | | typeof(DamageNumConfig),
|
| | | typeof(DirtyNameConfig),
|
| | | typeof(DirtyWordConfig),
|
| | | typeof(DungeonConfig),
|
| | | typeof(DungeonOpenTimeConfig),
|
| | | typeof(EffectConfig),
|
| | | typeof(EmojiPackConfig),
|
| | | typeof(FaceConfig),
|
| | | typeof(FamilyConfig),
|
| | | typeof(FamilyDonateConfig),
|
| | | typeof(FamilyEmblemConfig),
|
| | | typeof(FBDJGEffectConfig),
|
| | | typeof(FBDJGLevelConfig),
|
| | | typeof(FBDJGQuickConfig),
|
| | | typeof(FightPowerRatioConfig),
|
| | | typeof(FirstChargeConfig),
|
| | | typeof(FirstGoldConfig),
|
| | | typeof(FrameAnimationConfig),
|
| | | typeof(FuncOpenLVConfig),
|
| | | typeof(FunctionTeamSetConfig),
|
| | | typeof(GetItemWaysConfig),
|
| | | typeof(GmCmdConfig),
|
| | | typeof(GoldRushCampConfig),
|
| | | typeof(GoldRushItemConfig),
|
| | | typeof(GoldRushWorkerConfig),
|
| | | typeof(GubaoConfig),
|
| | | typeof(GubaoLVAttrConfig),
|
| | | typeof(GubaoLVConfig),
|
| | | typeof(GubaoResonanceAttrConfig),
|
| | | typeof(GubaoLVAttrConfig),
|
| | | typeof(GubaoResonanceConfig),
|
| | | typeof(GubaoResonanceAttrConfig),
|
| | | typeof(GubaoStarConfig),
|
| | | typeof(GuideConfig),
|
| | | typeof(HeroConfig),
|
| | | typeof(HeroAwakeConfig),
|
| | | typeof(HeroBreakConfig),
|
| | | typeof(HeroFatesConfig),
|
| | | typeof(HeroFatesQualityLVConfig),
|
| | | typeof(HeroFetterConfig),
|
| | | typeof(HeroLineupHaloConfig),
|
| | | typeof(HeroQualityConfig),
|
| | | typeof(HeroQualityAwakeConfig),
|
| | | typeof(HeroQualityBreakConfig),
|
| | | typeof(HeroQualityLVConfig),
|
| | | typeof(HeroSkinConfig),
|
| | | typeof(HeroSkinAttrConfig),
|
| | | typeof(HeroTalentConfig),
|
| | | typeof(HorseClassConfig),
|
| | | typeof(HorseIDConfig),
|
| | | typeof(HorseSkinConfig),
|
| | | typeof(ItemCompoundConfig),
|
| | | typeof(IconConfig),
|
| | | typeof(ItemConfig),
|
| | | typeof(ItemCompoundConfig),
|
| | | typeof(KickOutReasonConfig),
|
| | | typeof(LanguageConfig),
|
| | | typeof(LineupRecommendConfig),
|
| | | typeof(LLMJConfig),
|
| | | typeof(MailConfig),
|
| | | typeof(MainChapterConfig),
|
| | | typeof(MainLevelConfig),
|
| | | typeof(MGGanwuLVConfig),
|
| | |
| | | typeof(OrderInfoConfig),
|
| | | typeof(PlayerAttrConfig),
|
| | | typeof(PlayerFaceConfig),
|
| | | typeof(PlayerFacePicConfig),
|
| | | typeof(PlayerLVConfig),
|
| | | typeof(PlayerPropertyConfig),
|
| | | typeof(PopWinOrderConfig),
|
| | | typeof(PresetUnlockConfig),
|
| | | typeof(PriorBundleConfig),
|
| | | typeof(RandomNameConfig),
|
| | | typeof(RealmConfig),
|
| | | typeof(RealmLVUPTaskConfig),
|
| | | typeof(RichTextMsgReplaceConfig),
|
| | | typeof(RobotConfig),
|
| | | typeof(RuleConfig),
|
| | | typeof(SignInConfig),
|
| | | typeof(SkillConfig),
|
| | | typeof(SkillSkinConfig),
|
| | | typeof(StoreConfig),
|
| | | typeof(SuccessConfig),
|
| | | typeof(SysInfoConfig),
|
| | | typeof(TaskConfig),
|
| | | typeof(TianziConfig),
|
| | | typeof(TimingGiftConfig),
|
| | | typeof(TimingGiftTypeConfig),
|
| | |
| | | typeof(TitleStarUpConfig),
|
| | | typeof(TravelEventConfig),
|
| | | typeof(TravelSceneryConfig),
|
| | | typeof(TreasureCntAwardConfig),
|
| | | typeof(TreasureItemLibConfig),
|
| | | typeof(TreasureSetConfig),
|
| | | typeof(TreeLVConfig),
|
| | | typeof(WindowSearchConfig),
|
| | |
| | | typeof(ZhanlingConfig)
|
| | | };
|
| | |
|
| | | #if UNITY_EDITOR
|
| | | HashSet<Type> configHashSet = new HashSet<Type>();
|
| | | if (System.IO.File.Exists(Application.dataPath + "/fastConfig.txt") && Launch.Instance.isOpenConfigTesting)
|
| | | {
|
| | | string[] strConfgsArr = System.IO.File.ReadAllLines(Application.dataPath + "/fastConfig.txt");
|
| | | foreach (string str in strConfgsArr)
|
| | | {
|
| | | Type tpy = Type.GetType(str);
|
| | | configHashSet.Add(tpy);
|
| | | }
|
| | | }
|
| | | // 编辑器下加入 评估加载时常
|
| | | foreach (var config in configHashSet)
|
| | | {
|
| | | if (!configTypes.Add(config))
|
| | | {
|
| | | Debug.LogWarning($"配置 {config.Name} 已经存在于 configTypes 中,跳过添加。");
|
| | | }
|
| | | }
|
| | | List<string> fastName = new List<string>();
|
| | | #endif
|
| | |
|
| | | int iterator = 0;
|
| | | int totalConfigs = configTypes.Count;
|
| | |
|
| | | #if UNITY_WEBGL && !UNITY_EDITOR
|
| | | // ============================================================
|
| | | // WebGL 优化:两阶段加载
|
| | | // 阶段1: 一次性并发发起所有 TextAsset 加载(同 bundle 只下载一次)
|
| | | // 阶段2: 从内存中分批解析,每批 Yield 防止浏览器卡死
|
| | | // ============================================================
|
| | |
|
| | | // 阶段1: 并发加载所有配置文本到内存
|
| | | Debug.Log("[ConfigManager] WebGL 阶段1: 批量加载配置文件...");
|
| | | var configList = configTypes.ToList();
|
| | | var configDataMap = new Dictionary<Type, string[]>(totalConfigs);
|
| | | var loadTasks = new List<UniTask>(totalConfigs);
|
| | |
|
| | | foreach (var configType in configList)
|
| | | {
|
| | | var ct = configType; // closure capture
|
| | | loadTasks.Add(LoadConfigTextAsync(ct).ContinueWith(texts =>
|
| | | {
|
| | | if (texts != null)
|
| | | configDataMap[ct] = texts;
|
| | | else
|
| | | Debug.LogError($"找不到配置文件: {ct.Name}");
|
| | | }));
|
| | | }
|
| | | await UniTask.WhenAll(loadTasks);
|
| | | loadingProgress = 0.5f; // 网络加载完成 50%
|
| | | Debug.Log($"[ConfigManager] WebGL 阶段1完成: {configDataMap.Count}/{totalConfigs} 个配置已加载到内存");
|
| | |
|
| | | // 阶段2: 从内存中分批解析初始化
|
| | | const int parseBatchSize = 10;
|
| | | int parsed = 0;
|
| | | foreach (var configType in configList)
|
| | | {
|
| | | if (configDataMap.TryGetValue(configType, out var texts))
|
| | | {
|
| | | InitConfigFromTexts(configType, texts);
|
| | | }
|
| | | parsed++;
|
| | | loadingProgress = 0.5f + 0.5f * parsed / totalConfigs;
|
| | |
|
| | | // 每 parseBatchSize 个让出主线程
|
| | | if (parsed % parseBatchSize == 0)
|
| | | await UniTask.Yield();
|
| | | }
|
| | | #else
|
| | | List<UniTask> loadTasks = new List<UniTask>();
|
| | |
|
| | | // 逐个加载配置并更新进度
|
| | | foreach (var configType in configTypes)
|
| | | {
|
| | | #if UNITY_EDITOR
|
| | | var sw = System.Diagnostics.Stopwatch.StartNew();
|
| | | LoadConfigByType(configType);
|
| | | sw.Stop();
|
| | | #if UNITY_EDITOR
|
| | | if (sw.ElapsedMilliseconds >= 500)
|
| | | {
|
| | | Debug.LogError($"加载配置 {configType.Name} 耗时较长: {sw.ElapsedMilliseconds} ms");
|
| | | }
|
| | | else if (sw.ElapsedMilliseconds <= 5)
|
| | | {
|
| | | fastName.Add(configType.Name);
|
| | | }
|
| | | Debug.Log($"加载配置: {configType.Name} 用时: {sw.ElapsedMilliseconds} ms");
|
| | | #endif
|
| | | loadingProgress = (float)(iterator++ + 1) / totalConfigs;
|
| | | }
|
| | | #if UNITY_EDITOR
|
| | | if (Launch.Instance.isOpenConfigTesting)
|
| | | {
|
| | | System.IO.File.WriteAllText(Application.dataPath + "/fastConfig.txt", string.Join("\n", fastName));
|
| | |
|
| | | //加载完后卸载
|
| | | foreach (var configType in configTypes)
|
| | | UniTask uniTask = LoadConfigByTypeAsync(configType).ContinueWith(() =>
|
| | | {
|
| | | var methodInfo = configType.GetMethod("ForceRelease", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | if (methodInfo != null)
|
| | | #if UNITY_EDITOR
|
| | | if (sw.ElapsedMilliseconds >= 100)
|
| | | {
|
| | | methodInfo.Invoke(null, null);
|
| | | Debug.LogWarning($"加载配置 {configType.Name} 耗时较长: {sw.ElapsedMilliseconds} ms");
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.Log($"加载配置: {configType.Name} 用时: {sw.ElapsedMilliseconds} ms");
|
| | | }
|
| | | sw.Stop();
|
| | | #endif
|
| | |
|
| | | loadingProgress = (float)(++iterator) / totalConfigs;
|
| | | });
|
| | | |
| | | loadTasks.Add(uniTask);
|
| | |
|
| | | }
|
| | |
|
| | | await UniTask.WhenAll(loadTasks);
|
| | | #endif
|
| | |
|
| | | // 加载完成后设置isLoadFinished为true
|
| | |
| | | isLoadFinished = true;
|
| | | }
|
| | |
|
| | | public void LoadConfigByType(Type configType)
|
| | | // public void LoadConfigByType(Type configType)
|
| | | // {
|
| | | // string configName = configType.Name;
|
| | | // if (configName.EndsWith("Config"))
|
| | | // {
|
| | | // configName = configName.Substring(0, configName.Length - 6);
|
| | | // }
|
| | | // #pragma warning disable CS0618 // Obsolete — sync legacy fallback, use LoadConfigByTypeAsync
|
| | | // string[] texts = ResManager.Instance.LoadConfig(configName);
|
| | | // #pragma warning restore CS0618
|
| | | // if (texts != null)
|
| | | // {
|
| | | // string[] lines = texts;
|
| | | // var methodInfo = configType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | // if (methodInfo != null)
|
| | | // {
|
| | | // methodInfo.Invoke(null, new object[] { lines });
|
| | | // // 设置初始化标志
|
| | | // var isInitField = configType.GetField("isInit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
| | | // if (isInitField != null)
|
| | | // {
|
| | | // isInitField.SetValue(null, true);
|
| | | // }
|
| | | // Debug.Log($"加载配置: {configType.Name} 成功");
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // Debug.LogError($"配置类 {configType.Name} 没有静态Init方法");
|
| | | // }
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // Debug.LogError($"找不到配置文件: {configName}");
|
| | | // }
|
| | | // }
|
| | |
|
| | | /// <summary>
|
| | | /// US2: Async variant of LoadConfigByType. Uses UniTask-based config loading.
|
| | | /// </summary>
|
| | | public async UniTask LoadConfigByTypeAsync(Type configType)
|
| | | {
|
| | | string configName = configType.Name;
|
| | | if (configName.EndsWith("Config"))
|
| | | {
|
| | | configName = configName.Substring(0, configName.Length - 6);
|
| | | }
|
| | | string[] texts = ResManager.Instance.LoadConfig(configName);
|
| | | string[] texts = await ResManager.Instance.LoadConfigAsync(configName);
|
| | | if (texts != null)
|
| | | {
|
| | | string[] lines = texts;
|
| | | var methodInfo = configType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | var methodInfo = configType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | if (methodInfo != null)
|
| | | {
|
| | | methodInfo.Invoke(null, new object[] { lines });
|
| | | // 设置初始化标志
|
| | | methodInfo.Invoke(null, new object[] { texts });
|
| | | var isInitField = configType.GetField("isInit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
| | | if (isInitField != null)
|
| | | {
|
| | | isInitField.SetValue(null, true);
|
| | | }
|
| | | Debug.Log($"加载配置: {configType.Name} 成功");
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private async UniTask LoadConfig<T>() where T : class
|
| | | {
|
| | | string configName = typeof(T).Name;
|
| | | // private async UniTask LoadConfig<T>() where T : class
|
| | | // {
|
| | | // string configName = typeof(T).Name;
|
| | |
|
| | | string[] texts = ResManager.Instance.LoadConfig(configName);
|
| | | if (texts != null)
|
| | | {
|
| | | string[] lines = texts;
|
| | | var methodInfo = typeof(T).GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
| | | if (methodInfo != null)
|
| | | {
|
| | | methodInfo.Invoke(null, lines);
|
| | | // 设置初始化标志
|
| | | var isInitField = typeof(T).GetField("isInit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
| | | if (isInitField != null)
|
| | | {
|
| | | isInitField.SetValue(null, true);
|
| | | }
|
| | | Debug.Log($"加载配置: {typeof(T).Name} 成功");
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogError($"配置类 {typeof(T).Name} 没有静态Init方法");
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogError($"找不到配置文件: {configName}");
|
| | | }
|
| | | }
|
| | | // #pragma warning disable CS0618
|
| | | // string[] texts = ResManager.Instance.LoadConfig(configName);
|
| | | // #pragma warning restore CS0618
|
| | | // if (texts != null)
|
| | | // {
|
| | | // string[] lines = texts;
|
| | | // var methodInfo = typeof(T).GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
| | | // if (methodInfo != null)
|
| | | // {
|
| | | // methodInfo.Invoke(null, lines);
|
| | | // // 设置初始化标志
|
| | | // var isInitField = typeof(T).GetField("isInit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
| | | // if (isInitField != null)
|
| | | // {
|
| | | // isInitField.SetValue(null, true);
|
| | | // }
|
| | | // Debug.Log($"加载配置: {typeof(T).Name} 成功");
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // Debug.LogError($"配置类 {typeof(T).Name} 没有静态Init方法");
|
| | | // }
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // Debug.LogError($"找不到配置文件: {configName}");
|
| | | // }
|
| | | // }
|
| | |
|
| | | public float GetLoadingProgress()
|
| | | {
|
| | |
| | | {
|
| | | // 清空 ActBillboardAwardConfig 字典
|
| | | ClearConfigDictionary<ActBillboardAwardConfig>();
|
| | | // 清空 ActHeroAppearArtConfig 字典
|
| | | ClearConfigDictionary<ActHeroAppearArtConfig>();
|
| | | // 清空 ActHeroAppearConfig 字典
|
| | | ClearConfigDictionary<ActHeroAppearConfig>();
|
| | | // 清空 ActHeroAppearArtConfig 字典
|
| | | ClearConfigDictionary<ActHeroAppearArtConfig>();
|
| | | // 清空 ActHeroAppearStarConfig 字典
|
| | | ClearConfigDictionary<ActHeroAppearStarConfig>();
|
| | | // 清空 ActHeroReturnArtConfig 字典
|
| | | ClearConfigDictionary<ActHeroReturnArtConfig>();
|
| | | // 清空 ActLunhuidianTypeConfig 字典
|
| | | ClearConfigDictionary<ActLunhuidianTypeConfig>();
|
| | | // 清空 ActSignAwardConfig 字典
|
| | | ClearConfigDictionary<ActSignAwardConfig>();
|
| | | // 清空 ActSignConfig 字典
|
| | | ClearConfigDictionary<ActSignConfig>();
|
| | | // 清空 ActSignAwardConfig 字典
|
| | | ClearConfigDictionary<ActSignAwardConfig>();
|
| | | // 清空 ActSpecialSaleConfig 字典
|
| | | ClearConfigDictionary<ActSpecialSaleConfig>();
|
| | | // 清空 ActTaskConfig 字典
|
| | |
| | | ClearConfigDictionary<ActTotDayRechargeTempConfig>();
|
| | | // 清空 ADAwardConfig 字典
|
| | | ClearConfigDictionary<ADAwardConfig>();
|
| | | // 清空 AppointItemConfig 字典
|
| | | ClearConfigDictionary<AppointItemConfig>();
|
| | | // 清空 AudioConfig 字典
|
| | | ClearConfigDictionary<AudioConfig>();
|
| | | // 清空 BattleMapConfig 字典
|
| | | ClearConfigDictionary<BattleMapConfig>();
|
| | | // 清空 BeautyConfig 字典
|
| | |
| | | ClearConfigDictionary<BeautyQualityLVConfig>();
|
| | | // 清空 BeautySkinConfig 字典
|
| | | ClearConfigDictionary<BeautySkinConfig>();
|
| | | // 清空 ChatBubbleBoxConfig 字典
|
| | | ClearConfigDictionary<ChatBubbleBoxConfig>();
|
| | | // 清空 ChestsConfig 字典
|
| | | ClearConfigDictionary<ChestsConfig>();
|
| | | // 清空 ChestsAwardConfig 字典
|
| | | ClearConfigDictionary<ChestsAwardConfig>();
|
| | | // 清空 CTGConfig 字典
|
| | | ClearConfigDictionary<CTGConfig>();
|
| | | // 清空 CTGSelectItemConfig 字典
|
| | | ClearConfigDictionary<CTGSelectItemConfig>();
|
| | | // 清空 DailyLivenessRewardConfig 字典
|
| | | ClearConfigDictionary<DailyLivenessRewardConfig>();
|
| | | // 清空 DailyTaskConfig 字典
|
| | | ClearConfigDictionary<DailyTaskConfig>();
|
| | | // 清空 DamageNumConfig 字典
|
| | | ClearConfigDictionary<DamageNumConfig>();
|
| | | // 清空 DirtyNameConfig 字典
|
| | | ClearConfigDictionary<DirtyNameConfig>();
|
| | | // 清空 DirtyWordConfig 字典
|
| | | ClearConfigDictionary<DirtyWordConfig>();
|
| | | // 清空 DungeonConfig 字典
|
| | | ClearConfigDictionary<DungeonConfig>();
|
| | | // 清空 DungeonOpenTimeConfig 字典
|
| | | ClearConfigDictionary<DungeonOpenTimeConfig>();
|
| | | // 清空 EffectConfig 字典
|
| | | ClearConfigDictionary<EffectConfig>();
|
| | | // 清空 EmojiPackConfig 字典
|
| | | ClearConfigDictionary<EmojiPackConfig>();
|
| | | // 清空 FaceConfig 字典
|
| | | ClearConfigDictionary<FaceConfig>();
|
| | | // 清空 FamilyConfig 字典
|
| | | ClearConfigDictionary<FamilyConfig>();
|
| | | // 清空 FamilyDonateConfig 字典
|
| | | ClearConfigDictionary<FamilyDonateConfig>();
|
| | | // 清空 FamilyEmblemConfig 字典
|
| | | ClearConfigDictionary<FamilyEmblemConfig>();
|
| | | // 清空 FBDJGEffectConfig 字典
|
| | | ClearConfigDictionary<FBDJGEffectConfig>();
|
| | | // 清空 FBDJGLevelConfig 字典
|
| | |
| | | ClearConfigDictionary<FightPowerRatioConfig>();
|
| | | // 清空 FirstChargeConfig 字典
|
| | | ClearConfigDictionary<FirstChargeConfig>();
|
| | | // 清空 FirstGoldConfig 字典
|
| | | ClearConfigDictionary<FirstGoldConfig>();
|
| | | // 清空 FrameAnimationConfig 字典
|
| | | ClearConfigDictionary<FrameAnimationConfig>();
|
| | | // 清空 FuncOpenLVConfig 字典
|
| | | ClearConfigDictionary<FuncOpenLVConfig>();
|
| | | // 清空 FunctionTeamSetConfig 字典
|
| | | ClearConfigDictionary<FunctionTeamSetConfig>();
|
| | | // 清空 GetItemWaysConfig 字典
|
| | | ClearConfigDictionary<GetItemWaysConfig>();
|
| | | // 清空 GmCmdConfig 字典
|
| | | ClearConfigDictionary<GmCmdConfig>();
|
| | | // 清空 GoldRushCampConfig 字典
|
| | | ClearConfigDictionary<GoldRushCampConfig>();
|
| | | // 清空 GoldRushItemConfig 字典
|
| | |
| | | ClearConfigDictionary<GoldRushWorkerConfig>();
|
| | | // 清空 GubaoConfig 字典
|
| | | ClearConfigDictionary<GubaoConfig>();
|
| | | // 清空 GubaoLVAttrConfig 字典
|
| | | ClearConfigDictionary<GubaoLVAttrConfig>();
|
| | | // 清空 GubaoLVConfig 字典
|
| | | ClearConfigDictionary<GubaoLVConfig>();
|
| | | // 清空 GubaoResonanceAttrConfig 字典
|
| | | ClearConfigDictionary<GubaoResonanceAttrConfig>();
|
| | | // 清空 GubaoLVAttrConfig 字典
|
| | | ClearConfigDictionary<GubaoLVAttrConfig>();
|
| | | // 清空 GubaoResonanceConfig 字典
|
| | | ClearConfigDictionary<GubaoResonanceConfig>();
|
| | | // 清空 GubaoResonanceAttrConfig 字典
|
| | | ClearConfigDictionary<GubaoResonanceAttrConfig>();
|
| | | // 清空 GubaoStarConfig 字典
|
| | | ClearConfigDictionary<GubaoStarConfig>();
|
| | | // 清空 GuideConfig 字典
|
| | | ClearConfigDictionary<GuideConfig>();
|
| | | // 清空 HeroConfig 字典
|
| | | ClearConfigDictionary<HeroConfig>();
|
| | | // 清空 HeroAwakeConfig 字典
|
| | | ClearConfigDictionary<HeroAwakeConfig>();
|
| | | // 清空 HeroBreakConfig 字典
|
| | | ClearConfigDictionary<HeroBreakConfig>();
|
| | | // 清空 HeroFatesConfig 字典
|
| | | ClearConfigDictionary<HeroFatesConfig>();
|
| | | // 清空 HeroFatesQualityLVConfig 字典
|
| | | ClearConfigDictionary<HeroFatesQualityLVConfig>();
|
| | | // 清空 HeroFetterConfig 字典
|
| | | ClearConfigDictionary<HeroFetterConfig>();
|
| | | // 清空 HeroLineupHaloConfig 字典
|
| | | ClearConfigDictionary<HeroLineupHaloConfig>();
|
| | | // 清空 HeroQualityConfig 字典
|
| | | ClearConfigDictionary<HeroQualityConfig>();
|
| | | // 清空 HeroQualityAwakeConfig 字典
|
| | | ClearConfigDictionary<HeroQualityAwakeConfig>();
|
| | | // 清空 HeroQualityBreakConfig 字典
|
| | | ClearConfigDictionary<HeroQualityBreakConfig>();
|
| | | // 清空 HeroQualityLVConfig 字典
|
| | | ClearConfigDictionary<HeroQualityLVConfig>();
|
| | | // 清空 HeroSkinConfig 字典
|
| | | ClearConfigDictionary<HeroSkinConfig>();
|
| | | // 清空 HeroSkinAttrConfig 字典
|
| | | ClearConfigDictionary<HeroSkinAttrConfig>();
|
| | | // 清空 HeroTalentConfig 字典
|
| | | ClearConfigDictionary<HeroTalentConfig>();
|
| | | // 清空 HorseClassConfig 字典
|
| | | ClearConfigDictionary<HorseClassConfig>();
|
| | | // 清空 HorseIDConfig 字典
|
| | | ClearConfigDictionary<HorseIDConfig>();
|
| | | // 清空 HorseSkinConfig 字典
|
| | | ClearConfigDictionary<HorseSkinConfig>();
|
| | | // 清空 ItemCompoundConfig 字典
|
| | | ClearConfigDictionary<ItemCompoundConfig>();
|
| | | // 清空 IconConfig 字典
|
| | | ClearConfigDictionary<IconConfig>();
|
| | | // 清空 ItemConfig 字典
|
| | | ClearConfigDictionary<ItemConfig>();
|
| | | // 清空 ItemCompoundConfig 字典
|
| | | ClearConfigDictionary<ItemCompoundConfig>();
|
| | | // 清空 KickOutReasonConfig 字典
|
| | | ClearConfigDictionary<KickOutReasonConfig>();
|
| | | // 清空 LanguageConfig 字典
|
| | | ClearConfigDictionary<LanguageConfig>();
|
| | | // 清空 LineupRecommendConfig 字典
|
| | | ClearConfigDictionary<LineupRecommendConfig>();
|
| | | // 清空 LLMJConfig 字典
|
| | | ClearConfigDictionary<LLMJConfig>();
|
| | | // 清空 MailConfig 字典
|
| | | ClearConfigDictionary<MailConfig>();
|
| | | // 清空 MainChapterConfig 字典
|
| | | ClearConfigDictionary<MainChapterConfig>();
|
| | | // 清空 MainLevelConfig 字典
|
| | |
| | | ClearConfigDictionary<PlayerAttrConfig>();
|
| | | // 清空 PlayerFaceConfig 字典
|
| | | ClearConfigDictionary<PlayerFaceConfig>();
|
| | | // 清空 PlayerFacePicConfig 字典
|
| | | ClearConfigDictionary<PlayerFacePicConfig>();
|
| | | // 清空 PlayerLVConfig 字典
|
| | | ClearConfigDictionary<PlayerLVConfig>();
|
| | | // 清空 PlayerPropertyConfig 字典
|
| | | ClearConfigDictionary<PlayerPropertyConfig>();
|
| | | // 清空 PopWinOrderConfig 字典
|
| | | ClearConfigDictionary<PopWinOrderConfig>();
|
| | | // 清空 PresetUnlockConfig 字典
|
| | |
| | | ClearConfigDictionary<PriorBundleConfig>();
|
| | | // 清空 RandomNameConfig 字典
|
| | | ClearConfigDictionary<RandomNameConfig>();
|
| | | // 清空 RealmConfig 字典
|
| | | ClearConfigDictionary<RealmConfig>();
|
| | | // 清空 RealmLVUPTaskConfig 字典
|
| | | ClearConfigDictionary<RealmLVUPTaskConfig>();
|
| | | // 清空 RichTextMsgReplaceConfig 字典
|
| | | ClearConfigDictionary<RichTextMsgReplaceConfig>();
|
| | | // 清空 RobotConfig 字典
|
| | | ClearConfigDictionary<RobotConfig>();
|
| | | // 清空 RuleConfig 字典
|
| | | ClearConfigDictionary<RuleConfig>();
|
| | | // 清空 SignInConfig 字典
|
| | | ClearConfigDictionary<SignInConfig>();
|
| | | // 清空 SkillConfig 字典
|
| | | ClearConfigDictionary<SkillConfig>();
|
| | | // 清空 SkillSkinConfig 字典
|
| | | ClearConfigDictionary<SkillSkinConfig>();
|
| | | // 清空 StoreConfig 字典
|
| | |
| | | ClearConfigDictionary<SuccessConfig>();
|
| | | // 清空 SysInfoConfig 字典
|
| | | ClearConfigDictionary<SysInfoConfig>();
|
| | | // 清空 TaskConfig 字典
|
| | | ClearConfigDictionary<TaskConfig>();
|
| | | // 清空 TianziConfig 字典
|
| | | ClearConfigDictionary<TianziConfig>();
|
| | | // 清空 TimingGiftConfig 字典
|
| | |
| | | ClearConfigDictionary<TravelEventConfig>();
|
| | | // 清空 TravelSceneryConfig 字典
|
| | | ClearConfigDictionary<TravelSceneryConfig>();
|
| | | // 清空 TreasureCntAwardConfig 字典
|
| | | ClearConfigDictionary<TreasureCntAwardConfig>();
|
| | | // 清空 TreasureItemLibConfig 字典
|
| | | ClearConfigDictionary<TreasureItemLibConfig>();
|
| | | // 清空 TreasureSetConfig 字典
|
| | | ClearConfigDictionary<TreasureSetConfig>();
|
| | | // 清空 TreeLVConfig 字典
|
| | |
| | | ClearConfigDictionary<ZhanlingConfig>();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 只加载配置文本,不做解析。用于 WebGL 批量预加载。
|
| | | /// </summary>
|
| | | private async UniTask<string[]> LoadConfigTextAsync(Type configType)
|
| | | {
|
| | | string configName = configType.Name;
|
| | | if (configName.EndsWith("Config"))
|
| | | configName = configName.Substring(0, configName.Length - 6);
|
| | | return await ResManager.Instance.LoadConfigAsync(configName);
|
| | | }
|
| | |
|
| | | #if UNITY_EDITOR
|
| | | [MenuItem("Tools/Config/自检")]
|
| | | public static void CheckAndGenerateFastConfig()
|
| | | /// <summary>
|
| | | /// Editor 自检:反射加载所有配置类并记录耗时。
|
| | | /// </summary>
|
| | | public async void SelfCheckAllConfigs()
|
| | | {
|
| | | // 获取 Editor Assembly
|
| | | var editorAsm = System.AppDomain.CurrentDomain.GetAssemblies()
|
| | |
| | | foreach (var className in checkClasses)
|
| | | {
|
| | | // 这里也要用 Editor Assembly 获取类型
|
| | | var configType = editorAsm.GetType(className) ?? Type.GetType(className);
|
| | | if (configType == null)
|
| | | var cfgType = editorAsm.GetType(className) ?? Type.GetType(className);
|
| | | if (cfgType == null)
|
| | | {
|
| | | Debug.LogWarning($"[自检] 未找到类型: {className}");
|
| | | continue;
|
| | |
| | | var sw = System.Diagnostics.Stopwatch.StartNew();
|
| | |
|
| | | // 反射调用静态Init方法
|
| | | string configName = configType.Name;
|
| | | string configName = cfgType.Name;
|
| | | if (configName.EndsWith("Config"))
|
| | | configName = configName.Substring(0, configName.Length - 6);
|
| | |
|
| | | string[] texts = ResManager.Instance.LoadConfig(configName);
|
| | | string[] texts = await ResManager.Instance.LoadConfigAsync(configName);
|
| | | if (texts != null)
|
| | | {
|
| | | string[] lines = texts;
|
| | | var methodInfo = configType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | var methodInfo = cfgType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | if (methodInfo != null)
|
| | | {
|
| | | methodInfo.Invoke(null, new object[] { lines });
|
| | |
| | |
|
| | | if (sw.ElapsedMilliseconds >= 500)
|
| | | {
|
| | | Debug.LogError($"[自检] 加载配置 {configType.Name} 耗时较长: {sw.ElapsedMilliseconds} ms");
|
| | | Debug.LogError($"[自检] 加载配置 {cfgType.Name} 耗时较长: {sw.ElapsedMilliseconds} ms");
|
| | | }
|
| | | else if (sw.ElapsedMilliseconds <= 5)
|
| | | {
|
| | | fastName.Add(configType.Name);
|
| | | fastName.Add(cfgType.Name);
|
| | | }
|
| | | Debug.Log($"[自检] 加载配置: {configType.Name} 用时: {sw.ElapsedMilliseconds} ms");
|
| | | Debug.Log($"[自检] 加载配置: {cfgType.Name} 用时: {sw.ElapsedMilliseconds} ms");
|
| | | }
|
| | |
|
| | | // 释放所有已加载的配置
|
| | | foreach (var className in checkClasses)
|
| | | {
|
| | | var configType = editorAsm.GetType(className) ?? Type.GetType(className);
|
| | | if (configType == null) continue;
|
| | | var methodInfo = configType.GetMethod("ForceRelease", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | var cfgType = editorAsm.GetType(className) ?? Type.GetType(className);
|
| | | if (cfgType == null) continue;
|
| | | var methodInfo = cfgType.GetMethod("ForceRelease", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | if (methodInfo != null)
|
| | | {
|
| | | methodInfo.Invoke(null, null);
|
| | |
| | | Debug.Log($"[自检] fastConfig.txt 生成完毕,快速表有:{string.Join(", ", fastName)}");
|
| | | }
|
| | | #endif
|
| | |
|
| | | /// <summary>
|
| | | /// 从已加载的文本初始化配置(纯内存操作,无网络)。
|
| | | /// </summary>
|
| | | private void InitConfigFromTexts(Type configType, string[] texts)
|
| | | {
|
| | | var methodInfo = configType.GetMethod("Init",
|
| | | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
|
| | | if (methodInfo != null)
|
| | | {
|
| | | methodInfo.Invoke(null, new object[] { texts });
|
| | | var isInitField = configType.GetField("isInit",
|
| | | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
| | | if (isInitField != null)
|
| | | isInitField.SetValue(null, true);
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogError($"配置类 {configType.Name} 没有静态Init方法");
|
| | | }
|
| | | }
|
| | |
|
| | | }
|