From 007b136724c7f238b8d25068a5b7cd07af08e326 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Fri, 5 May 2023 23:23:13 +0800 Subject: [PATCH] [+] ConfigUtility [+] ConfigUtility --- .../HotFix/GameProto/ConfigUtility.cs | 65 +++++++++++++++++++ .../HotFix/GameProto/ConfigUtility.cs.meta | 3 + 2 files changed, 68 insertions(+) create mode 100644 Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs create mode 100644 Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs.meta diff --git a/Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs b/Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs new file mode 100644 index 00000000..f75ca3f0 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using TEngine; + +namespace GameProto +{ + /// + /// 指定Key委托。 + /// + /// 键。 + /// 值。 + public delegate TKey ConvertDictionaryKey(TValue val); + + /// + /// 配置表辅助工具。 + /// + public static class ConfigUtility + { + /// + /// 生成64long的主键。 + /// + /// 键1。 + /// 键2。 + /// 64long的主键。 + public static UInt64 Make64Key(uint key1, uint key2) + { + return ((UInt64)key1 << 32) | key2; + } + + /// + /// 拷贝配置表字典。 + /// + /// 拷贝地址。 + /// 拷贝源。 + /// 指定主键。 + /// 键。 + /// 值。 + /// 是否拷贝成功。 + public static bool CopyConfigDict(ref Dictionary dict,List source, ConvertDictionaryKey convKey) + { + if (source == null) + { + return false; + } + + dict.Clear(); + + bool failed = false; + for (int i = 0; i < source.Count; i++) + { + var data = source[i]; + TKey key = convKey(data); + if (dict.ContainsKey(key)) + { + Log.Fatal("Copy Config Failed: {0} IndexOf {1} Had Repeated Key: {2} ", typeof(TValue).Name, i + 1, key); + failed = true; + break; + } + + dict.Add(key, data); + } + return !failed; + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs.meta b/Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs.meta new file mode 100644 index 00000000..a9c0c92c --- /dev/null +++ b/Assets/GameScripts/HotFix/GameProto/ConfigUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e278e636820842f293e2a765962ad4f8 +timeCreated: 1683300170 \ No newline at end of file