├── .gitignore ├── Doc └── configtool.png ├── ExcelToCode.sln ├── ExcelToCode ├── Configs │ ├── NLog.config │ ├── Template │ │ ├── Client │ │ │ ├── Bean.template │ │ │ ├── Container.template │ │ │ ├── GameDataManager.template │ │ │ └── LanBean.template │ │ └── Server │ │ │ ├── Bean.template │ │ │ ├── Container.template │ │ │ ├── GameDataManager.template │ │ │ └── LanBean.template │ └── config.xml ├── Excel │ ├── DataIllegalException.cs │ ├── DataMgrInfo.cs │ ├── DataType.cs │ ├── ExcelReader.cs │ ├── ExportHelper.cs │ ├── Field.cs │ └── SheetHeadInfo.cs ├── ExcelToCode - Backup.csproj ├── ExcelToCode.csproj ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs └── Utils │ ├── DllLoader.cs │ ├── FileUtil.cs │ ├── LogUtil.cs │ ├── Setting.cs │ ├── StringUtils.cs │ ├── TimeUtils.cs │ └── XBuffer.cs ├── README.md ├── Test ├── Base │ ├── ConfigManager.cs │ ├── Debuger.cs │ └── SingletonTemplate.cs ├── Program.cs ├── Test.csproj ├── XBuffer.cs └── code │ ├── Data │ ├── Beans │ │ ├── t_globalBean.cs │ │ ├── t_languageBean.cs │ │ └── t_monsterBean.cs │ └── Containers │ │ ├── t_globalContainer.cs │ │ ├── t_languageContainer.cs │ │ └── t_monsterContainer.cs │ └── GameDataManager.cs └── output ├── data ├── client │ ├── t_globalBean.bytes │ ├── t_languageBean.bytes │ └── t_monsterBean.bytes └── server │ ├── t_globalBean.bytes │ ├── t_languageBean.bytes │ └── t_monsterBean.bytes └── excel ├── 0 语言包.xlsx ├── 1 全局表.xlsx └── 6 怪物表.xlsx /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /Doc/configtool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/Doc/configtool.png -------------------------------------------------------------------------------- /ExcelToCode.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32519.379 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExcelToCode", "ExcelToCode\ExcelToCode.csproj", "{19EBE99B-FD27-48EC-A21F-8207EA92AD43}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{F4C09DDC-B49F-40DF-813B-F2A7B6C192DC}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {19EBE99B-FD27-48EC-A21F-8207EA92AD43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {19EBE99B-FD27-48EC-A21F-8207EA92AD43}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {19EBE99B-FD27-48EC-A21F-8207EA92AD43}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {19EBE99B-FD27-48EC-A21F-8207EA92AD43}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {F4C09DDC-B49F-40DF-813B-F2A7B6C192DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F4C09DDC-B49F-40DF-813B-F2A7B6C192DC}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F4C09DDC-B49F-40DF-813B-F2A7B6C192DC}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F4C09DDC-B49F-40DF-813B-F2A7B6C192DC}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {CDCBE5D6-959B-4CC5-BFC8-2DA559C174C9} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ExcelToCode/Configs/NLog.config: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Client/Bean.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Data.Containers; 5 | using Base; 6 | 7 | namespace Data.Beans 8 | { 9 | ///{{SheetNameDesc}} 10 | public class {{BeanClassName}} : BaseBin 11 | { 12 | {%- for field in Fields -%} 13 | {%- if field.Datatype == "textmult" -%} 14 | private int m_{{field.Name}}; 15 | ///{{field.Desc}} 16 | public string {{field.name}} 17 | { 18 | get 19 | { 20 | if(m_{{field.Name}} == 0) 21 | return ""; 22 | t_languageBean lanBean = ConfigBean.GetBean(m_{{field.Name}}); 23 | if (lanBean != null) 24 | return lanBean.t_content; 25 | else 26 | return m_{{field.Name}}.ToString(); 27 | } 28 | } 29 | {%- else -%} 30 | ///{{field.Desc}} 31 | public {{field.Datatype}} {{field.Name}}; 32 | {%- endif -%} 33 | {%- endfor -%} 34 | 35 | public void LoadData(byte[] data, ref int offset) 36 | { 37 | {%- for field in Fields -%} 38 | {%- if field.Datatype == "int" -%} 39 | {{field.Name}} = XBuffer.ReadInt(data, ref offset); 40 | {%- elsif field.Datatype == "long" -%} 41 | {{field.Name}} = XBuffer.ReadLong(data, ref offset); 42 | {%- elsif field.Datatype == "textmult" -%} 43 | m_{{field.Name}} = XBuffer.ReadInt(data, ref offset); 44 | {%- elsif field.Datatype == "string" -%} 45 | {{field.Name}} = XBuffer.ReadString(data, ref offset); 46 | {%- endif -%} 47 | {%- endfor -%} 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Client/Container.template: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/ExcelToCode/Configs/Template/Client/Container.template -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Client/GameDataManager.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Base; 5 | using System; 6 | using Data.Beans; 7 | using Data.Containers; 8 | using System.Collections; 9 | using System.Collections.Generic; 10 | 11 | namespace Data.Containers 12 | { 13 | public class GameDataManager 14 | { 15 | public static readonly GameDataManager Instance = new GameDataManager(); 16 | {%- for container in containers -%} 17 | public {{container}} {{container}} = new {{container}}(); 18 | {%- endfor -%} 19 | //@%@%@ 20 | private GameDataManager() 21 | { 22 | {%- for container in containers -%} 23 | t_containerMap.Add({{container}}.BinType, {{container}}); 24 | {%- endfor -%} 25 | //@#@#@ 26 | } 27 | 28 | public void LoadAll(bool forceReload = false) 29 | { 30 | {%- for container in containers -%} 31 | LoadOneBean({{container}}.BinType, forceReload); 32 | {%- endfor -%} 33 | //@*@*@ 34 | } 35 | 36 | //bin -- container dictionary 37 | private Dictionary t_containerMap = new Dictionary(); 38 | 39 | public T GetBin(K key, bool ignoreErrLog) where T : BaseBin 40 | { 41 | Type t = typeof(T); 42 | LoadOneBean(t); 43 | if(t_containerMap.ContainsKey(t)) 44 | { 45 | var t_container = t_containerMap[t]; 46 | Dictionary map = t_container.getMap() as Dictionary; 47 | if(map != null && map.ContainsKey(key)) 48 | return map[key]; 49 | //UnityEngine.Debug.LogError("T,K get > " + t.Name + "," + typeof(K).Name + " should be > " + t_container.getMap()); 50 | } 51 | if(false == ignoreErrLog) 52 | Debuger.Err("can not find Bin > " + t.Name + " id > " + key); 53 | return null; 54 | } 55 | 56 | public List GetBinList() where T : BaseBin 57 | { 58 | Type t = typeof(T); 59 | LoadOneBean(t); 60 | if(t_containerMap.ContainsKey(t)) 61 | { 62 | var t_container = t_containerMap[t]; 63 | List list = t_container.getList() as List; 64 | if(list != null) 65 | return list; 66 | Debuger.Err("can not find Bin > " + t.Name); 67 | } 68 | Debuger.Err("can not find Bin > " + t.Name); 69 | return null; 70 | } 71 | 72 | public Dictionary GetBinMap() where T : BaseBin 73 | { 74 | Type t = typeof(T); 75 | LoadOneBean(t); 76 | if(t_containerMap.ContainsKey(t)) 77 | { 78 | var t_container = t_containerMap[t]; 79 | Dictionary map = t_container.getMap() as Dictionary; 80 | if(map != null) 81 | return map; 82 | Debuger.Err("T,K get > " + t.Name + "," + typeof(K).Name + " should be > " + t_container.getMap()); 83 | } 84 | return null; 85 | } 86 | 87 | public void LoadOneBean(bool forceReload = false) where T : BaseBin 88 | { 89 | Type t = typeof(T); 90 | LoadOneBean(t, forceReload); 91 | } 92 | 93 | public void LoadOneBean(Type t, bool forceReload = false) 94 | { 95 | if (t_containerMap.ContainsKey(t)) 96 | { 97 | if (!t_containerMap[t].Loaded || forceReload) 98 | { 99 | t_containerMap[t].loadDataFromBin(); 100 | } 101 | } 102 | } 103 | } 104 | 105 | public class BaseContainer 106 | { 107 | public bool Loaded { get; protected set; } 108 | public virtual IList getList() 109 | { 110 | return null; 111 | } 112 | 113 | public virtual IDictionary getMap() 114 | { 115 | return null; 116 | } 117 | 118 | public virtual void loadDataFromBin() 119 | { 120 | 121 | } 122 | } 123 | 124 | public class BaseBin 125 | { 126 | } 127 | } 128 | 129 | public class ConfigBean 130 | { 131 | public static bool IsServer; 132 | /// 133 | ///T -----> Bean 134 | ///K -----> id type (int/string) 135 | /// 136 | public static T GetBean(K id, bool ignoreErrLog = false) where T : BaseBin 137 | { 138 | return GameDataManager.Instance.GetBin(id, ignoreErrLog); 139 | } 140 | 141 | /// 142 | /// Get Table Data By List 143 | /// 144 | public static List GetBeanList() where T : BaseBin 145 | { 146 | return GameDataManager.Instance.GetBinList(); 147 | } 148 | 149 | /// 150 | /// Get Table Data By Map 151 | /// 152 | public static Dictionary GetBeanMap() where T : BaseBin 153 | { 154 | return GameDataManager.Instance.GetBinMap(); 155 | } 156 | } 157 | 158 | public static class ConfigExtension 159 | { 160 | public static string GetItsLanaugeStr(this int id) 161 | { 162 | var bean = ConfigBean.GetBean(id); 163 | if(bean != null) 164 | return bean.t_content; 165 | return id.ToString(); 166 | } 167 | 168 | public static string GetItsGlobalStr(this int id) 169 | { 170 | var bean = ConfigBean.GetBean(id); 171 | if(bean != null) 172 | return bean.t_string_param; 173 | return ""; 174 | } 175 | 176 | public static int GetItsGlobalInt(this int id) 177 | { 178 | var bean = ConfigBean.GetBean(id); 179 | if(bean != null) 180 | return bean.t_int_param; 181 | return 0; 182 | } 183 | } -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Client/LanBean.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | * {{SheetNameDesc}} 4 | */ 5 | using Data.Containers; 6 | using Base; 7 | 8 | namespace Data.Beans 9 | { 10 | public class {{BeanClassName}} : BaseBin 11 | { 12 | 13 | public int t_id; 14 | public string t_content; 15 | 16 | public void LoadData(byte[] data, ref int offset) 17 | { 18 | 19 | string useField = ConfigManager.Singleton.Language; 20 | {%- for field in Fields -%} 21 | {%- if field.Datatype == "int" -%} 22 | {{field.Name}} = XBuffer.ReadInt(data, ref offset); 23 | {%- elsif field.Datatype == "string" -%} 24 | 25 | if (string.IsNullOrEmpty(t_content) && useField == "{{field.Name}}") 26 | { 27 | t_content = XBuffer.ReadString(data, ref offset); 28 | } 29 | else 30 | { 31 | //ignore no need language 32 | short slen = XBuffer.ReadShort(data, ref offset); 33 | offset += slen; 34 | } 35 | 36 | {%- endif -%} 37 | {%- endfor -%} 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Server/Bean.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Data.Containers; 5 | using Base; 6 | 7 | namespace Data.Beans 8 | { 9 | ///{{SheetNameDesc}} 10 | public class {{BeanClassName}} : BaseBin 11 | { 12 | {%- for field in Fields -%} 13 | {%- if field.Datatype == "textmult" -%} 14 | private int m_{{field.Name}}; 15 | ///{{field.Desc}} 16 | public string {{field.name}} 17 | { 18 | get 19 | { 20 | if(m_{{field.Name}} == 0) 21 | return ""; 22 | t_languageBean lanBean = ConfigBean.GetBean(m_{{field.Name}}); 23 | if (lanBean != null) 24 | return lanBean.t_content; 25 | else 26 | return m_{{field.Name}}.ToString(); 27 | } 28 | } 29 | {%- else -%} 30 | ///{{field.Desc}} 31 | public {{field.Datatype}} {{field.Name}}; 32 | {%- endif -%} 33 | {%- endfor -%} 34 | 35 | public void LoadData(byte[] data, ref int offset) 36 | { 37 | {%- for field in Fields -%} 38 | {%- if field.Datatype == "int" -%} 39 | {{field.Name}} = XBuffer.ReadInt(data, ref offset); 40 | {%- elsif field.Datatype == "long" -%} 41 | {{field.Name}} = XBuffer.ReadLong(data, ref offset); 42 | {%- elsif field.Datatype == "textmult" -%} 43 | m_{{field.Name}} = XBuffer.ReadInt(data, ref offset); 44 | {%- elsif field.Datatype == "string" -%} 45 | {{field.Name}} = XBuffer.ReadString(data, ref offset); 46 | {%- endif -%} 47 | {%- endfor -%} 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Server/Container.template: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/ExcelToCode/Configs/Template/Server/Container.template -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Server/GameDataManager.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Base; 5 | using System; 6 | using Data.Beans; 7 | using Data.Containers; 8 | using System.Collections; 9 | using System.Collections.Generic; 10 | 11 | namespace Data.Containers 12 | { 13 | public class GameDataManager 14 | { 15 | public static readonly GameDataManager Instance = new GameDataManager(); 16 | {%- for container in containers -%} 17 | public {{container}} {{container}} = new {{container}}(); 18 | {%- endfor -%} 19 | //@%@%@ 20 | private GameDataManager() 21 | { 22 | {%- for container in containers -%} 23 | t_containerMap.Add({{container}}.BinType, {{container}}); 24 | {%- endfor -%} 25 | //@#@#@ 26 | } 27 | 28 | public void LoadAll(bool forceReload = false) 29 | { 30 | {%- for container in containers -%} 31 | LoadOneBean({{container}}.BinType, forceReload); 32 | {%- endfor -%} 33 | //@*@*@ 34 | } 35 | 36 | //bin -- container dictionary 37 | private Dictionary t_containerMap = new Dictionary(); 38 | 39 | public T GetBin(K key, bool ignoreErrLog) where T : BaseBin 40 | { 41 | Type t = typeof(T); 42 | LoadOneBean(t); 43 | if(t_containerMap.ContainsKey(t)) 44 | { 45 | var t_container = t_containerMap[t]; 46 | Dictionary map = t_container.getMap() as Dictionary; 47 | if(map != null && map.ContainsKey(key)) 48 | return map[key]; 49 | //UnityEngine.Debug.LogError("T,K get > " + t.Name + "," + typeof(K).Name + " should be > " + t_container.getMap()); 50 | } 51 | if(false == ignoreErrLog) 52 | Debuger.Err("can not find Bin > " + t.Name + " id > " + key); 53 | return null; 54 | } 55 | 56 | public List GetBinList() where T : BaseBin 57 | { 58 | Type t = typeof(T); 59 | LoadOneBean(t); 60 | if(t_containerMap.ContainsKey(t)) 61 | { 62 | var t_container = t_containerMap[t]; 63 | List list = t_container.getList() as List; 64 | if(list != null) 65 | return list; 66 | Debuger.Err("can not find Bin > " + t.Name); 67 | } 68 | Debuger.Err("can not find Bin > " + t.Name); 69 | return null; 70 | } 71 | 72 | public Dictionary GetBinMap() where T : BaseBin 73 | { 74 | Type t = typeof(T); 75 | LoadOneBean(t); 76 | if(t_containerMap.ContainsKey(t)) 77 | { 78 | var t_container = t_containerMap[t]; 79 | Dictionary map = t_container.getMap() as Dictionary; 80 | if(map != null) 81 | return map; 82 | Debuger.Err("T,K get > " + t.Name + "," + typeof(K).Name + " should be > " + t_container.getMap()); 83 | } 84 | return null; 85 | } 86 | 87 | public void LoadOneBean(bool forceReload = false) where T : BaseBin 88 | { 89 | Type t = typeof(T); 90 | LoadOneBean(t, forceReload); 91 | } 92 | 93 | public void LoadOneBean(Type t, bool forceReload = false) 94 | { 95 | if (t_containerMap.ContainsKey(t)) 96 | { 97 | if (!t_containerMap[t].Loaded || forceReload) 98 | { 99 | t_containerMap[t].loadDataFromBin(); 100 | } 101 | } 102 | } 103 | } 104 | 105 | public class BaseContainer 106 | { 107 | public bool Loaded { get; protected set; } 108 | public virtual IList getList() 109 | { 110 | return null; 111 | } 112 | 113 | public virtual IDictionary getMap() 114 | { 115 | return null; 116 | } 117 | 118 | public virtual void loadDataFromBin() 119 | { 120 | 121 | } 122 | } 123 | 124 | public class BaseBin 125 | { 126 | } 127 | } 128 | 129 | public class ConfigBean 130 | { 131 | public static bool IsServer; 132 | /// 133 | ///T -----> Bean 134 | ///K -----> id type (int/string) 135 | /// 136 | public static T GetBean(K id, bool ignoreErrLog = false) where T : BaseBin 137 | { 138 | return GameDataManager.Instance.GetBin(id, ignoreErrLog); 139 | } 140 | 141 | /// 142 | /// Get Table Data By List 143 | /// 144 | public static List GetBeanList() where T : BaseBin 145 | { 146 | return GameDataManager.Instance.GetBinList(); 147 | } 148 | 149 | /// 150 | /// Get Table Data By Map 151 | /// 152 | public static Dictionary GetBeanMap() where T : BaseBin 153 | { 154 | return GameDataManager.Instance.GetBinMap(); 155 | } 156 | } 157 | 158 | public static class ConfigExtension 159 | { 160 | public static string GetItsLanaugeStr(this int id) 161 | { 162 | var bean = ConfigBean.GetBean(id); 163 | if(bean != null) 164 | return bean.t_content; 165 | return id.ToString(); 166 | } 167 | 168 | public static string GetItsGlobalStr(this int id) 169 | { 170 | var bean = ConfigBean.GetBean(id); 171 | if(bean != null) 172 | return bean.t_string_param; 173 | return ""; 174 | } 175 | 176 | public static int GetItsGlobalInt(this int id) 177 | { 178 | var bean = ConfigBean.GetBean(id); 179 | if(bean != null) 180 | return bean.t_int_param; 181 | return 0; 182 | } 183 | } -------------------------------------------------------------------------------- /ExcelToCode/Configs/Template/Server/LanBean.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | * {{SheetNameDesc}} 4 | */ 5 | using Data.Containers; 6 | using Base; 7 | 8 | namespace Data.Beans 9 | { 10 | public class {{BeanClassName}} : BaseBin 11 | { 12 | 13 | public int t_id; 14 | public string t_content; 15 | 16 | public void LoadData(byte[] data, ref int offset) 17 | { 18 | 19 | string useField = ConfigManager.Singleton.Language; 20 | {%- for field in Fields -%} 21 | {%- if field.Datatype == "int" -%} 22 | {{field.Name}} = XBuffer.ReadInt(data, ref offset); 23 | {%- elsif field.Datatype == "string" -%} 24 | 25 | if (string.IsNullOrEmpty(t_content) && useField == "{{field.Name}}") 26 | { 27 | t_content = XBuffer.ReadString(data, ref offset); 28 | } 29 | else 30 | { 31 | //ignore no need language 32 | short slen = XBuffer.ReadShort(data, ref offset); 33 | offset += slen; 34 | } 35 | 36 | {%- endif -%} 37 | {%- endfor -%} 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ExcelToCode/Configs/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ../../excel/ 4 | ../../../Test/code/ 5 | ../../data/server/ 6 | ../../../Test/code/ 7 | ../../data/client/ 8 | 5242880 9 | 5242880 10 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/DataIllegalException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExcelToCode.Excel 4 | { 5 | public class DataIllegalException : Exception 6 | { 7 | 8 | public DataIllegalException(string message) 9 | :base(message) 10 | { 11 | 12 | } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/DataMgrInfo.cs: -------------------------------------------------------------------------------- 1 | using DotLiquid; 2 | using System.Collections.Generic; 3 | 4 | namespace ExcelToCode.Excel 5 | { 6 | public class DataMgrInfo : Drop 7 | { 8 | public List Containers { get; set; } 9 | 10 | public DataMgrInfo() 11 | { 12 | Containers = new List(); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/DataType.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelToCode.Excel 2 | { 3 | public static class DataType 4 | { 5 | 6 | public const string Int = "int"; 7 | 8 | public const string String = "string"; 9 | 10 | public const string Long = "long"; 11 | 12 | public const string Float = "float"; 13 | 14 | public const string Text = "text"; 15 | 16 | public const string TextMult = "textmult"; 17 | 18 | public static bool IsLegal(string type) 19 | { 20 | //默认为int类型 21 | if (string.IsNullOrEmpty(type)) 22 | type = "int"; 23 | return (type == Int || type == Text || type == TextMult 24 | || type == Long || type == String); 25 | } 26 | 27 | public static string GetTrueTyped(string type) 28 | { 29 | //默认为int类型 30 | if (string.IsNullOrEmpty(type)) 31 | type = "int"; 32 | if (type == Text || type == String) 33 | return String; 34 | return type; 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/ExcelReader.cs: -------------------------------------------------------------------------------- 1 | using OfficeOpenXml; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using NLog; 6 | using ExcelConverter.Utils; 7 | using System.Drawing; 8 | 9 | namespace ExcelToCode.Excel 10 | { 11 | public class ExcelReader 12 | { 13 | 14 | private static readonly NLog.Logger LOGGER = LogManager.GetCurrentClassLogger(); 15 | 16 | /// 17 | /// 导出类型行号 18 | /// 19 | public static int ExportTypeRow = 1; 20 | /// 21 | /// 字段名字行号 22 | /// 23 | public static int FieldNameRow = 2; 24 | /// 25 | /// 字段数据类型行号 26 | /// 27 | public static int FieldTypeRow = 3; 28 | /// 29 | /// 字段导出类型行号 30 | /// 31 | public static int FieldExportTypeRow = 4; 32 | /// 33 | /// 字段描述行号 34 | /// 35 | public static int FieldDescRow = 5; 36 | /// 37 | /// 字段描述行号 38 | /// 39 | public static int DataStartRow = 6; 40 | /// 41 | /// 主键列号 42 | /// 43 | public static int PrimaryKeyCol = 1; 44 | 45 | /// 46 | /// 表头信息( 用生成代码,只会返回合法的表单) 47 | /// 48 | /// 49 | /// 50 | public List ReadHeadInfo(string filePath, ExportType exportType, out ExcelPackage outPackage) 51 | { 52 | List res = new List(); 53 | ExcelPackage.LicenseContext = LicenseContext.NonCommercial; 54 | ExcelPackage package = new ExcelPackage(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); 55 | package.File = new FileInfo(filePath); 56 | outPackage = package; 57 | List validList = IsLegal(package, exportType); 58 | if (validList != null && validList.Count > 0) 59 | { 60 | for (int i = 0; i < validList.Count; ++i) 61 | { 62 | ExcelWorksheet sheet = package.Workbook.Worksheets[validList[i]]; 63 | SheetHeadInfo headInfo = new SheetHeadInfo(); 64 | //记录表单id 65 | headInfo.SheetId = validList[i]; 66 | //表单名字 67 | headInfo.SheetName = StringUtils.Trim(sheet.Name); //去除空格 68 | headInfo.BeanClassName = headInfo.SheetName + "Bean"; 69 | headInfo.ContainerClassName = headInfo.SheetName + "Container"; 70 | 71 | //导出类型 72 | string etype = Obj2String(sheet.GetValue(ExportTypeRow, PrimaryKeyCol)); 73 | headInfo.Etype = GetExportType(etype); 74 | 75 | //表单名字描述 76 | string sheetDesc = Obj2String(sheet.GetValue(FieldExportTypeRow, PrimaryKeyCol)); 77 | if (sheetDesc == null) 78 | sheetDesc = ""; 79 | else 80 | sheetDesc = StringUtils.Trim(sheetDesc); //去除空格 81 | headInfo.SheetNameDesc = sheetDesc; 82 | 83 | //获取该表主键类型 84 | string keyStr = Obj2String(sheet.GetValue(FieldTypeRow, PrimaryKeyCol)); 85 | if (string.IsNullOrEmpty(keyStr)) 86 | keyStr = "int"; 87 | if (DataType.IsLegal(keyStr)) 88 | headInfo.PrimaryKeyType = DataType.GetTrueTyped(keyStr); 89 | 90 | //收集有效字段 91 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 92 | { 93 | bool needExport = false; 94 | if (j == sheet.Dimension.Start.Column) 95 | { 96 | needExport = true; 97 | } 98 | else 99 | { 100 | string estr = Obj2String(sheet.GetValue(FieldExportTypeRow, j)); 101 | ExportType exType = GetExportType(estr); 102 | if (exType == ExportType.Both || exType == exportType) 103 | { 104 | needExport = true; 105 | } 106 | else if (exType == ExportType.Unknown) 107 | { 108 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, string.Format("未知的导出类型{0}行{1}列[{2}]", FieldNameRow, j, estr)); 109 | continue; 110 | } 111 | } 112 | string str = Obj2String(sheet.GetValue(FieldNameRow, j)); 113 | if (str != null && str.StartsWith("t_") && needExport) 114 | { 115 | Field field = new Field(); 116 | field.Name = StringUtils.Trim(str); //去除空格 117 | field.Col = j; 118 | field.Row = FieldNameRow; 119 | if (!headInfo.ValidFiledsName.ContainsKey(field.Name)) 120 | { 121 | headInfo.AddFiled(j, field); 122 | headInfo.ValidFiledsName.Add(field.Name, field.Name); 123 | } 124 | else 125 | { 126 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, string.Format("重复的字段名{0}行{1}列[{2}]", FieldNameRow, j, field.Name)); 127 | //若需跳过本张表,考虑使用break 128 | continue; 129 | } 130 | } 131 | } 132 | 133 | //收集有效字段数据类型 134 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 135 | { 136 | if (headInfo.ValidFileds.ContainsKey(j)) 137 | { 138 | string str = Obj2String(sheet.GetValue(FieldTypeRow, j)); 139 | Field field = headInfo.ValidFileds[j]; 140 | if (field != null) 141 | { 142 | if (DataType.IsLegal(str)) 143 | { 144 | field.Datatype = DataType.GetTrueTyped(str); 145 | } 146 | else 147 | { 148 | LOGGER.Error("未知的数据类型{}行{}列", FieldTypeRow, j); 149 | //throw new DataIllegalException(string.Format("未知的数据类型{0}行{1}列", FieldTypeRow, j)); 150 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, string.Format("错误数据类型{0}行{1}列", FieldTypeRow, j)); 151 | //若需跳过本张表,考虑使用break 152 | continue; 153 | } 154 | } 155 | } 156 | } 157 | 158 | //收集有效字段描述 159 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 160 | { 161 | if (headInfo.ValidFileds.ContainsKey(j)) 162 | { 163 | //string desc = Obj2String(sheet.GetValue(FieldDescRow, j)); 164 | //if (desc == null) 165 | // desc = ""; 166 | //headInfo.AddFiledDesc(j, desc); 167 | string str = Obj2String(sheet.GetValue(FieldDescRow, j)); 168 | Field field = headInfo.ValidFileds[j]; 169 | if (field != null) 170 | { 171 | if (str != null) 172 | str = StringUtils.Trim(str); //去除空格 173 | field.Desc = str; 174 | } 175 | } 176 | } 177 | 178 | res.Add(headInfo); 179 | } 180 | } 181 | return res; 182 | } 183 | 184 | public string Obj2String(object obj) 185 | { 186 | string str = ""; 187 | if (obj != null) 188 | str = obj.ToString(); 189 | return str; 190 | } 191 | 192 | /// 193 | /// 获取导出类型 194 | /// 195 | /// 196 | /// 197 | private ExportType GetExportType(string type) 198 | { 199 | //不填的时候默认为都导出 200 | if (string.IsNullOrEmpty(type)) 201 | type = "cs"; 202 | //全部转换成小写 203 | type = type.ToLower().Trim(); 204 | if (type.Equals("cs") || type.Equals("sc")) 205 | return ExportType.Both; 206 | else if (type.Contains("c")) 207 | return ExportType.Client; 208 | else if (type.Contains("s")) 209 | return ExportType.Server; 210 | return ExportType.Unknown; 211 | } 212 | 213 | /// 214 | /// 表格是否合法 215 | /// 216 | /// 返回合法的表单id 217 | private List IsLegal(ExcelPackage package, ExportType exportType) 218 | { 219 | List list = new List(); 220 | if (package != null 221 | && package.Workbook != null 222 | && package.Workbook.Worksheets != null 223 | && package.Workbook.Worksheets.Count > 0) 224 | { 225 | for (int i = 0; i < package.Workbook.Worksheets.Count; ++i) 226 | { 227 | ExcelWorksheet sheet = package.Workbook.Worksheets[i]; 228 | //表名字必须以t_开头 229 | if (!sheet.Name.StartsWith("t_")) 230 | { 231 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "表名须以t_开头"); 232 | continue; 233 | } 234 | //从1行开始 235 | if (sheet.Dimension.Start.Row != 1) 236 | { 237 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "需从1行开始"); 238 | continue; 239 | } 240 | 241 | //从1列开始 242 | if (sheet.Dimension.Start.Column != 1) 243 | { 244 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "需从1列开始"); 245 | continue; 246 | } 247 | //至少有5行 248 | if (sheet.Dimension.End.Row < 5) 249 | { 250 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "至少有5行"); 251 | continue; 252 | } 253 | 254 | //至少有2列 255 | if (sheet.Dimension.End.Column < 2) 256 | { 257 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "至少有2列"); 258 | continue; 259 | } 260 | 261 | //导出类型 262 | string etype = Obj2String(sheet.GetValue(ExportTypeRow, PrimaryKeyCol)); 263 | var Etype = GetExportType(etype); 264 | if (Etype != ExportType.Both && Etype != exportType) 265 | { 266 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "此表不需要在" + exportType.ToString() + "中导出"); 267 | continue; 268 | } 269 | 270 | //第2行至少有两列数据合法 271 | int validColumnCount = 0; 272 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 273 | { 274 | string str = Obj2String(sheet.GetValue(FieldNameRow, j)); 275 | if (str != null && str.StartsWith("t_")) 276 | { 277 | validColumnCount++; 278 | if (validColumnCount > 2) 279 | break; 280 | } 281 | } 282 | if (validColumnCount < 2) 283 | { 284 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "第2行至少有两列数据字段"); 285 | continue; 286 | } 287 | 288 | if (!IsExportCountLegal(Etype, sheet)) 289 | { 290 | LogUtil.AddIgnoreLog(package.File.Name, sheet.Name, "导出字段个数需大于2"); 291 | continue; 292 | } 293 | 294 | //合法表单 295 | list.Add(i); 296 | } 297 | } 298 | return list; 299 | } 300 | 301 | 302 | public bool IsExportCountLegal(ExportType etype, ExcelWorksheet sheet) 303 | { 304 | int ccount = 0; 305 | int scount = 0; 306 | switch (etype) 307 | { 308 | case ExportType.Unknown: 309 | return false; 310 | case ExportType.Server: 311 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 312 | { 313 | //第一列必须全部导出 314 | if (j == 1) 315 | { 316 | ccount++; 317 | scount++; 318 | continue; 319 | } 320 | string str = Obj2String(sheet.GetValue(FieldExportTypeRow, j)); 321 | if (string.IsNullOrEmpty(str)) 322 | str = "cs"; 323 | str = str.ToLower(); 324 | if (str.Contains("s")) 325 | { 326 | scount++; 327 | } 328 | } 329 | return scount >= 2; 330 | case ExportType.Client: 331 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 332 | { 333 | //第一列必须全部导出 334 | if (j == 1) 335 | { 336 | ccount++; 337 | scount++; 338 | continue; 339 | } 340 | string str = Obj2String(sheet.GetValue(FieldExportTypeRow, j)); 341 | if (string.IsNullOrEmpty(str)) 342 | str = "cs"; 343 | str = str.ToLower(); 344 | if (str.Contains("c")) 345 | { 346 | ccount++; 347 | } 348 | } 349 | return ccount >= 2; 350 | case ExportType.Both: 351 | for (int j = sheet.Dimension.Start.Column, k = sheet.Dimension.End.Column; j <= k; j++) 352 | { 353 | //第一列必须全部导出 354 | if (j == 1) 355 | { 356 | ccount++; 357 | scount++; 358 | continue; 359 | } 360 | string str = Obj2String(sheet.GetValue(FieldExportTypeRow, j)); 361 | if (string.IsNullOrEmpty(str)) 362 | str = "cs"; 363 | str = str.ToLower(); 364 | if (str.Contains("cs") || str.Contains("sc")) 365 | { 366 | ccount++; 367 | scount++; 368 | } 369 | else if (str.Contains("c")) 370 | { 371 | ccount++; 372 | } 373 | else if (str.Contains("s")) 374 | { 375 | scount++; 376 | } 377 | } 378 | return ccount >= 2 && scount >= 2; 379 | default: 380 | return false; 381 | } 382 | } 383 | 384 | 385 | } 386 | } 387 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/ExportHelper.cs: -------------------------------------------------------------------------------- 1 | using DotLiquid; 2 | using ExcelConverter.Utils; 3 | using NLog; 4 | using OfficeOpenXml; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Threading.Tasks; 9 | 10 | namespace ExcelToCode.Excel 11 | { 12 | public class ExportHelper 13 | { 14 | 15 | private static readonly NLog.Logger LOGGER = LogManager.GetCurrentClassLogger(); 16 | 17 | /// 18 | /// 普通配置表缓存 19 | /// 20 | public static byte[] NormalBuffer = null; 21 | 22 | /// 23 | /// 语言包缓存 24 | /// 25 | public static byte[] LanguageBuffer = null; 26 | 27 | /// 28 | /// 是否初始化 29 | /// 30 | private static bool IsInited = false; 31 | 32 | public static void Init() 33 | { 34 | if (IsInited) 35 | return; 36 | IsInited = true; 37 | NormalBuffer = new byte[Setting.NormalBufferSize]; 38 | LanguageBuffer = new byte[Setting.LanguageBufferSize]; 39 | } 40 | 41 | public static void Export(ExportType etype, List fileList, bool isAll) 42 | { 43 | Init(); 44 | 45 | //只有全部导出的时候才清空,导出单个文件不清空 46 | if (isAll) 47 | { 48 | //清空原来的代码目录 49 | string path = Setting.GetCodePath(etype); 50 | if (!Directory.Exists(path)) 51 | Directory.CreateDirectory(path); 52 | else 53 | FileUtil.ClearDirectory(path); 54 | 55 | //清空原来的Bin目录 56 | path = Setting.GetBinPath(etype); 57 | if (!Directory.Exists(path)) 58 | Directory.CreateDirectory(path); 59 | else 60 | FileUtil.ClearDirectory(path); 61 | } 62 | 63 | DataMgrInfo mgrInfo = new DataMgrInfo(); 64 | for (int i = 0; i < fileList.Count; i++) 65 | { 66 | ExcelReader excelReader = new ExcelReader(); 67 | ExcelPackage package = null; 68 | List headInfos = excelReader.ReadHeadInfo(fileList[i], etype, out package); 69 | 70 | GenBin(headInfos, package, etype); 71 | //Task.Run(()=> { GenBin(headInfos, package, etype); }); 72 | GenBeanAddContainer(headInfos, etype, mgrInfo); 73 | 74 | 75 | LogUtil.AddNormalLog(package.File.Name, "导表完成"); 76 | 77 | if (package != null) 78 | package.Dispose(); 79 | } 80 | 81 | GenGameDataManager(mgrInfo, etype, isAll); 82 | ExcelToCode.Program.MainForm.ToggleAllBtn(true); 83 | LogUtil.Add("---------导表完成-------------"); 84 | } 85 | 86 | private static void GenBeanAddContainer(List headInfos, ExportType etype, DataMgrInfo mgrInfo) 87 | { 88 | string beanPath = Setting.GetCodePath(etype) + @"/Data/Beans/"; 89 | if(!Directory.Exists(beanPath)) 90 | Directory.CreateDirectory(beanPath); 91 | string containerPath = Setting.GetCodePath(etype) + @"/Data/Containers/"; 92 | if (!Directory.Exists(containerPath)) 93 | Directory.CreateDirectory(containerPath); 94 | 95 | 96 | string content = ""; 97 | string templatePath = Setting.GetTemplatePath(etype) + "/Bean.template"; 98 | Template template = Template.Parse(File.ReadAllText(templatePath)); 99 | foreach (var info in headInfos) 100 | { 101 | if (info.SheetName == "t_language") 102 | { 103 | string lanTemplatePath = Setting.GetTemplatePath(etype) + "/LanBean.template"; 104 | Template lanTemplate = Template.Parse(File.ReadAllText(lanTemplatePath)); 105 | content = lanTemplate.Render(Hash.FromAnonymousObject(info)); 106 | File.WriteAllText(beanPath + info.BeanClassName + ".cs", content); 107 | } 108 | else 109 | { 110 | content = template.Render(Hash.FromAnonymousObject(info)); 111 | File.WriteAllText(beanPath + info.BeanClassName + ".cs", content); 112 | } 113 | } 114 | 115 | templatePath = Setting.GetTemplatePath(etype) + "/Container.template"; 116 | template = Template.Parse(File.ReadAllText(templatePath)); 117 | foreach (var info in headInfos) 118 | { 119 | content = template.Render(Hash.FromAnonymousObject(info)); 120 | File.WriteAllText(containerPath + info.ContainerClassName + ".cs", content); 121 | } 122 | 123 | for (int i = 0; i < headInfos.Count; i++) 124 | { 125 | mgrInfo.Containers.Add(headInfos[i].ContainerClassName); 126 | } 127 | } 128 | 129 | private static void GenGameDataManager(DataMgrInfo mgrInfo, ExportType etype, bool isAll) 130 | { 131 | string path = Setting.GetCodePath(etype) + @"/GameDataManager.cs"; 132 | if (isAll || !File.Exists(path)) 133 | { 134 | string templatePath = Setting.GetTemplatePath(etype) + "/GameDataManager.template"; 135 | Template template = Template.Parse(File.ReadAllText(templatePath)); 136 | var str = template.Render(Hash.FromAnonymousObject(mgrInfo)); 137 | File.WriteAllText(Setting.GetCodePath(etype) + "GameDataManager.cs", str); 138 | } 139 | else 140 | { 141 | if (mgrInfo == null || mgrInfo.Containers.Count <= 0) 142 | return; 143 | string containerName = mgrInfo.Containers[0]; 144 | 145 | string part1 = string.Format("public {0} {1} = new {2}();", containerName, containerName, containerName); 146 | string part2 = string.Format("t_containerMap.Add({0}.BinType, {1});", containerName, containerName); 147 | string part3 = string.Format("LoadOneBean({0}.BinType, forceReload);", containerName); 148 | 149 | string content = File.ReadAllText(path); 150 | int index = content.IndexOf("@%@%@"); 151 | if (index != -1) 152 | { 153 | if(content.IndexOf(part1) < 0) 154 | content = content.Insert(index-6, "\r\n\t\t" + part1); 155 | } 156 | else 157 | { 158 | LogUtil.Add("找不到标记位:@%@%@", true); 159 | } 160 | 161 | index = content.IndexOf("@#@#@"); 162 | if (index != -1) 163 | { 164 | if (content.IndexOf(part2) < 0) 165 | content = content.Insert(index-6, "\r\n\t\t\t" + part2); 166 | } 167 | else 168 | { 169 | LogUtil.Add("找不到标记位:@#@#@", true); 170 | } 171 | 172 | index = content.IndexOf("@*@*@"); 173 | if (index != -1) 174 | { 175 | if (content.IndexOf(part3) < 0) 176 | content = content.Insert(index-6, "\r\n\t\t\t" + part3); 177 | } 178 | else 179 | { 180 | LogUtil.Add("找不到标记位:@*@*@", true); 181 | } 182 | 183 | File.WriteAllText(Setting.GetCodePath(etype) + "GameDataManager.cs", content); 184 | } 185 | } 186 | 187 | 188 | private static void GenBin(List headInfos, ExcelPackage package, ExportType etype) 189 | { 190 | for (int i = 0; i < headInfos.Count; i++) 191 | { 192 | SheetHeadInfo headInfo = headInfos[i]; 193 | ExcelWorksheet sheet = package.Workbook.Worksheets[headInfo.SheetId]; //只导出合法表单id的数据 194 | //空表没有数据 195 | if (ExcelReader.DataStartRow > sheet.Dimension.End.Row) 196 | continue; 197 | //首先清空缓冲区 198 | byte[] byteArr = null; 199 | if (headInfo.SheetName == "t_language") 200 | { 201 | Array.Clear(LanguageBuffer, 0, LanguageBuffer.Length); 202 | byteArr = LanguageBuffer; 203 | } 204 | else 205 | { 206 | Array.Clear(NormalBuffer, 0, NormalBuffer.Length); 207 | byteArr = NormalBuffer; 208 | } 209 | int offset = 0; 210 | //写入文件头----表名string-字段数量byte-字段类型byte (0:int 1:long 2:string 3:float) 211 | //XBuffer.WriteString(headInfos[i].SheetName, byteArr, ref offset); 212 | XBuffer.WriteInt(headInfos[i].Fields.Count, byteArr, ref offset); 213 | for (int k = 0; k < headInfos[i].Fields.Count; k++) 214 | { 215 | Field field = headInfos[i].Fields[k]; 216 | switch (field.Datatype) 217 | { 218 | case DataType.Int: 219 | case DataType.TextMult: 220 | XBuffer.WriteByte(0, byteArr, ref offset); 221 | break; 222 | case DataType.Long: 223 | XBuffer.WriteByte(1, byteArr, ref offset); 224 | break; 225 | case DataType.Text: 226 | case DataType.String: 227 | XBuffer.WriteByte(2, byteArr, ref offset); 228 | break; 229 | case DataType.Float: 230 | XBuffer.WriteByte(3, byteArr, ref offset); 231 | break; 232 | default: 233 | //抛异常 234 | break; 235 | } 236 | 237 | 238 | } 239 | for (int k = 0; k < headInfo.Fields.Count; k++) 240 | { 241 | var content = ""; 242 | Field field = headInfo.Fields[k]; 243 | content = field.Name; 244 | if (string.IsNullOrEmpty(content)) 245 | content = ""; 246 | content = content.Trim(); 247 | //处理换行符 248 | content = content.Replace(@"\n", "\n"); 249 | XBuffer.WriteString(content, byteArr, ref offset); 250 | } 251 | 252 | headInfo.ContentStartOffset = offset; 253 | 254 | //写入数据 255 | for (int m = ExcelReader.DataStartRow, n = sheet.Dimension.End.Row; m <= n; m++) 256 | { 257 | //为了严格保证有序,遍历List,不遍历dictionary 258 | //foreach (KeyValuePair item in headInfos[i].ValidFileds) 259 | for (int j = 0; j < headInfos[i].Fields.Count; j++) 260 | { 261 | int col = headInfos[i].Fields[j].Col; 262 | Field field = headInfos[i].Fields[j]; 263 | 264 | var content = ""; 265 | var obj = sheet.GetValue(m, col); 266 | if (obj != null) 267 | content = obj.ToString(); 268 | 269 | //排除id为0的数据行 270 | if (j == 0 && string.IsNullOrEmpty(content)) 271 | { 272 | break; 273 | } 274 | 275 | switch (field.Datatype) 276 | { 277 | case DataType.Int: 278 | case DataType.TextMult: 279 | int intVal = 0; 280 | int.TryParse(content, out intVal); 281 | XBuffer.WriteInt(intVal, byteArr, ref offset); 282 | break; 283 | case DataType.Text: 284 | case DataType.String: 285 | if (string.IsNullOrEmpty(content)) 286 | content = ""; 287 | content = content.Trim(); 288 | //处理换行符 289 | content = content.Replace(@"\n", "\n"); 290 | XBuffer.WriteString(content, byteArr, ref offset); 291 | break; 292 | case DataType.Float: 293 | float floatVal = 0; 294 | float.TryParse(content, out floatVal); 295 | XBuffer.WriteFloat(floatVal, byteArr, ref offset); 296 | break; 297 | case DataType.Long: 298 | long longVal = 0; 299 | long.TryParse(content, out longVal); 300 | XBuffer.WriteLong(longVal, byteArr, ref offset); 301 | break; 302 | default: 303 | //抛异常 304 | break; 305 | } 306 | } 307 | } 308 | //将数据写入磁盘 309 | System.IO.File.WriteAllBytes(Setting.GetBinPath(etype) + headInfo.SheetName + "Bean.bytes", GetValidData(byteArr, offset)); 310 | } 311 | } 312 | 313 | /// 314 | /// 获取Byte数组内有效数据 315 | /// 316 | /// 317 | /// 318 | /// 319 | public static byte[] GetValidData(byte[] org, int validLen) 320 | { 321 | if (validLen > org.Length) 322 | { 323 | LOGGER.Error("数据异常org:{},valid:{}", org.Length, validLen); 324 | return org; 325 | } 326 | byte[] res = new byte[validLen]; 327 | Array.Copy(org, 0, res, 0, validLen); 328 | return res; 329 | } 330 | 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/Field.cs: -------------------------------------------------------------------------------- 1 | using DotLiquid; 2 | using System; 3 | 4 | namespace ExcelToCode.Excel 5 | { 6 | public class Field : Drop 7 | { 8 | public int Col; 9 | 10 | public int Row; 11 | 12 | /// 13 | /// 字段名 14 | /// 15 | public string Name { set; get; } 16 | 17 | /// 18 | /// 数据类型(驼峰命名会被模板拆分为DataType==>Data_Type) 19 | /// (为保证模板和类属性一致,故用小写) 20 | /// 21 | public string Datatype { set; get; } 22 | 23 | /// 24 | /// 字段描述 25 | /// 26 | public string Desc { get; set; } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ExcelToCode/Excel/SheetHeadInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using DotLiquid; 3 | using NLog; 4 | 5 | namespace ExcelToCode.Excel 6 | { 7 | 8 | public enum ExportType 9 | { 10 | Unknown, 11 | Client, 12 | Server, 13 | Both 14 | } 15 | 16 | public class SheetHeadInfo : Drop 17 | { 18 | private static readonly NLog.Logger LOGGER = LogManager.GetCurrentClassLogger(); 19 | 20 | /// 21 | /// 表格id 22 | /// 23 | public int SheetId { set; get; } 24 | 25 | /// 26 | /// 表单名字 27 | /// 28 | public string SheetName { set; get; } 29 | 30 | /// 31 | /// 表单名字说明 32 | /// 33 | public string SheetNameDesc { set; get; } 34 | 35 | /// 36 | /// 导出类型 37 | /// 38 | public ExportType Etype = ExportType.Both; 39 | 40 | 41 | /// 42 | /// Bean类名字 43 | /// 44 | public string BeanClassName { set; get; } 45 | 46 | /// 47 | /// 容器类名字 48 | /// 49 | public string ContainerClassName { set; get; } 50 | 51 | /// 52 | /// 主键类型 53 | /// 54 | public string PrimaryKeyType { set; get; } 55 | 56 | /// 57 | /// 有效的字段 58 | /// 59 | public List Fields { get; private set; } 60 | 61 | /// 62 | /// 有效的字段 63 | /// 64 | public Dictionary ValidFileds { get; private set; } 65 | 66 | /// 67 | /// 字段数量 68 | /// 69 | public int FieldCount 70 | { 71 | get 72 | { 73 | if(Fields == null) 74 | return 0; 75 | return Fields.Count; 76 | } 77 | } 78 | 79 | public int ContentStartOffset { get; set; } 80 | 81 | /// 82 | /// 83 | /// 84 | public Dictionary ValidFiledsName { get; private set; } 85 | 86 | public SheetHeadInfo() 87 | { 88 | ValidFileds = new Dictionary(); 89 | ValidFiledsName = new Dictionary(); 90 | Fields = new List(); 91 | } 92 | 93 | public void AddFiled(int key, Field field) 94 | { 95 | if (!ValidFileds.ContainsKey(key)) 96 | { 97 | ValidFileds.Add(key, field); 98 | Fields.Add(field); 99 | } 100 | else 101 | { 102 | LOGGER.Info("重复添加key:{}", key); 103 | } 104 | } 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /ExcelToCode/ExcelToCode - Backup.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | disable 7 | true 8 | enable 9 | True 10 | ..\output\debug\ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | PreserveNewest 22 | 23 | 24 | PreserveNewest 25 | 26 | 27 | PreserveNewest 28 | 29 | 30 | PreserveNewest 31 | 32 | 33 | PreserveNewest 34 | 35 | 36 | PreserveNewest 37 | 38 | 39 | PreserveNewest 40 | 41 | 42 | PreserveNewest 43 | 44 | 45 | PreserveNewest 46 | 47 | 48 | PreserveNewest 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /ExcelToCode/ExcelToCode.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | disable 7 | true 8 | enable 9 | True 10 | ..\output\app\ 11 | 12 | 13 | 14 | false 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | PreserveNewest 26 | 27 | 28 | PreserveNewest 29 | 30 | 31 | PreserveNewest 32 | 33 | 34 | PreserveNewest 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | PreserveNewest 41 | 42 | 43 | PreserveNewest 44 | 45 | 46 | PreserveNewest 47 | 48 | 49 | PreserveNewest 50 | 51 | 52 | PreserveNewest 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /ExcelToCode/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelToCode 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.configListBox = new System.Windows.Forms.CheckedListBox(); 32 | this.logTb = new System.Windows.Forms.TextBox(); 33 | this.errLogTb = new System.Windows.Forms.TextBox(); 34 | this.ServerAll = new System.Windows.Forms.Button(); 35 | this.ServerSingle = new System.Windows.Forms.Button(); 36 | this.clearLogBtn = new System.Windows.Forms.Button(); 37 | this.ClientAll = new System.Windows.Forms.Button(); 38 | this.ClientSingle = new System.Windows.Forms.Button(); 39 | this.clearErrLogBtn = new System.Windows.Forms.Button(); 40 | this.SuspendLayout(); 41 | // 42 | // configListBox 43 | // 44 | this.configListBox.FormattingEnabled = true; 45 | this.configListBox.Location = new System.Drawing.Point(1, 0); 46 | this.configListBox.Name = "configListBox"; 47 | this.configListBox.Size = new System.Drawing.Size(632, 310); 48 | this.configListBox.TabIndex = 0; 49 | // 50 | // logTb 51 | // 52 | this.logTb.Location = new System.Drawing.Point(1, 357); 53 | this.logTb.Multiline = true; 54 | this.logTb.Name = "logTb"; 55 | this.logTb.Size = new System.Drawing.Size(243, 203); 56 | this.logTb.TabIndex = 1; 57 | // 58 | // errLogTb 59 | // 60 | this.errLogTb.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); 61 | this.errLogTb.Location = new System.Drawing.Point(250, 357); 62 | this.errLogTb.Multiline = true; 63 | this.errLogTb.Name = "errLogTb"; 64 | this.errLogTb.Size = new System.Drawing.Size(383, 203); 65 | this.errLogTb.TabIndex = 2; 66 | // 67 | // ServerAll 68 | // 69 | this.ServerAll.Location = new System.Drawing.Point(18, 316); 70 | this.ServerAll.Name = "ServerAll"; 71 | this.ServerAll.Size = new System.Drawing.Size(82, 32); 72 | this.ServerAll.TabIndex = 3; 73 | this.ServerAll.Text = "服务器-ALL"; 74 | this.ServerAll.UseVisualStyleBackColor = true; 75 | this.ServerAll.Click += new System.EventHandler(this.ServerAll_Click); 76 | // 77 | // ServerSingle 78 | // 79 | this.ServerSingle.Location = new System.Drawing.Point(114, 316); 80 | this.ServerSingle.Name = "ServerSingle"; 81 | this.ServerSingle.Size = new System.Drawing.Size(82, 32); 82 | this.ServerSingle.TabIndex = 3; 83 | this.ServerSingle.Text = "服务器-单选"; 84 | this.ServerSingle.UseVisualStyleBackColor = true; 85 | this.ServerSingle.Click += new System.EventHandler(this.ServerSingle_Click); 86 | // 87 | // clearLogBtn 88 | // 89 | this.clearLogBtn.Location = new System.Drawing.Point(210, 316); 90 | this.clearLogBtn.Name = "clearLogBtn"; 91 | this.clearLogBtn.Size = new System.Drawing.Size(82, 32); 92 | this.clearLogBtn.TabIndex = 3; 93 | this.clearLogBtn.Text = "清理日志"; 94 | this.clearLogBtn.UseVisualStyleBackColor = true; 95 | this.clearLogBtn.Click += new System.EventHandler(this.ClearLogBtn_Click); 96 | // 97 | // ClientAll 98 | // 99 | this.ClientAll.Location = new System.Drawing.Point(327, 317); 100 | this.ClientAll.Name = "ClientAll"; 101 | this.ClientAll.Size = new System.Drawing.Size(82, 32); 102 | this.ClientAll.TabIndex = 3; 103 | this.ClientAll.Text = "客户端-ALL"; 104 | this.ClientAll.UseVisualStyleBackColor = true; 105 | this.ClientAll.Click += new System.EventHandler(this.ClientAll_Click); 106 | // 107 | // ClientSingle 108 | // 109 | this.ClientSingle.Location = new System.Drawing.Point(424, 317); 110 | this.ClientSingle.Name = "ClientSingle"; 111 | this.ClientSingle.Size = new System.Drawing.Size(82, 32); 112 | this.ClientSingle.TabIndex = 3; 113 | this.ClientSingle.Text = "客户端-单选"; 114 | this.ClientSingle.UseVisualStyleBackColor = true; 115 | this.ClientSingle.Click += new System.EventHandler(this.ClientSingle_Click); 116 | // 117 | // clearErrLogBtn 118 | // 119 | this.clearErrLogBtn.Location = new System.Drawing.Point(521, 317); 120 | this.clearErrLogBtn.Name = "clearErrLogBtn"; 121 | this.clearErrLogBtn.Size = new System.Drawing.Size(82, 32); 122 | this.clearErrLogBtn.TabIndex = 3; 123 | this.clearErrLogBtn.Text = "清理日志"; 124 | this.clearErrLogBtn.UseVisualStyleBackColor = true; 125 | this.clearErrLogBtn.Click += new System.EventHandler(this.ClearErrLogBtn_Click); 126 | // 127 | // Form1 128 | // 129 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); 130 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 131 | this.ClientSize = new System.Drawing.Size(634, 561); 132 | this.Controls.Add(this.clearErrLogBtn); 133 | this.Controls.Add(this.ClientSingle); 134 | this.Controls.Add(this.ClientAll); 135 | this.Controls.Add(this.clearLogBtn); 136 | this.Controls.Add(this.ServerSingle); 137 | this.Controls.Add(this.ServerAll); 138 | this.Controls.Add(this.errLogTb); 139 | this.Controls.Add(this.logTb); 140 | this.Controls.Add(this.configListBox); 141 | this.Name = "Form1"; 142 | this.Text = "导表工具"; 143 | this.Load += new System.EventHandler(this.OnFormLoaded); 144 | this.ResumeLayout(false); 145 | this.PerformLayout(); 146 | 147 | } 148 | 149 | #endregion 150 | 151 | private CheckedListBox configListBox; 152 | private TextBox logTb; 153 | private TextBox errLogTb; 154 | private Button ServerAll; 155 | private Button ServerSingle; 156 | private Button clearLogBtn; 157 | private Button ClientAll; 158 | private Button ClientSingle; 159 | private Button clearErrLogBtn; 160 | } 161 | } -------------------------------------------------------------------------------- /ExcelToCode/Form1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/ExcelToCode/Form1.cs -------------------------------------------------------------------------------- /ExcelToCode/Form1.resx: -------------------------------------------------------------------------------- 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 | text/microsoft-resx 50 | 51 | 52 | 2.0 53 | 54 | 55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 56 | 57 | 58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 59 | 60 | -------------------------------------------------------------------------------- /ExcelToCode/Program.cs: -------------------------------------------------------------------------------- 1 | namespace ExcelToCode 2 | { 3 | internal static class Program 4 | { 5 | public static Form1 MainForm = null; 6 | 7 | /// 8 | /// The main entry point for the application. 9 | /// 10 | [STAThread] 11 | static void Main() 12 | { 13 | // To customize application configuration such as set high DPI settings or default font, 14 | // see https://aka.ms/applicationconfiguration. 15 | ApplicationConfiguration.Initialize(); 16 | //Application.Run(new Form1()); 17 | MainForm = new Form1(); 18 | Application.Run(MainForm); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /ExcelToCode/Utils/DllLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace ExcelConverter.Utils 5 | { 6 | public class DllLoader 7 | { 8 | public static void Load() 9 | { 10 | //https://www.cnblogs.com/lip-blog/p/7365942.html 11 | AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => 12 | { 13 | String resourceName = "ExcelConverter.libs." + new AssemblyName(args.Name).Name + ".dll"; 14 | using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) 15 | { 16 | Byte[] assemblyData = new Byte[stream.Length]; 17 | stream.Read(assemblyData, 0, assemblyData.Length); 18 | return Assembly.Load(assemblyData); 19 | } 20 | }; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ExcelToCode/Utils/FileUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ExcelConverter.Utils 9 | { 10 | public class FileUtil 11 | { 12 | 13 | public static void ClearDirectory(string path, bool recursion = true, string filter = "") 14 | { 15 | List fileList = GetFileList(path, true, filter); 16 | foreach (string filePath in fileList) 17 | { 18 | File.Delete(filePath); 19 | } 20 | } 21 | 22 | public static List GetFileList(string path, bool recursion = false, string filter="") 23 | { 24 | List fileList = new List(); 25 | if (!Directory.Exists(path)) 26 | return fileList; 27 | DirectoryInfo dir = new DirectoryInfo(path); 28 | System.IO.FileInfo[] fil = dir.GetFiles(); 29 | foreach (System.IO.FileInfo f in fil) 30 | { 31 | if (!string.IsNullOrEmpty(filter)) 32 | { 33 | if (filter.Contains(".xlsx") && f.Name.Contains("~$")) 34 | continue; 35 | filter = filter.ToLower(); 36 | if (filter.IndexOf(f.Extension.ToLower()) >= 0) 37 | fileList.Add(f.FullName); 38 | } 39 | else 40 | { 41 | fileList.Add(f.FullName); 42 | } 43 | } 44 | //获取子文件夹内的文件列表,递归遍历 45 | if (recursion) 46 | { 47 | DirectoryInfo[] dii = dir.GetDirectories(); 48 | foreach (DirectoryInfo d in dii) 49 | { 50 | fileList.AddRange(GetFileList(d.FullName, recursion)); 51 | } 52 | } 53 | return fileList; 54 | } 55 | 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ExcelToCode/Utils/LogUtil.cs: -------------------------------------------------------------------------------- 1 |  2 | using NLog; 3 | using System.Text; 4 | using System.Windows.Forms; 5 | 6 | public class LogUtil 7 | { 8 | 9 | private static readonly NLog.Logger LOGGER = LogManager.GetCurrentClassLogger(); 10 | 11 | private static TextBox normalLogTb; 12 | 13 | private static TextBox errorLogTb; 14 | 15 | public static void Init(TextBox tb, TextBox errTb) 16 | { 17 | normalLogTb = tb; 18 | errorLogTb = errTb; 19 | } 20 | 21 | public static void Add(string log, bool isErr = false) 22 | { 23 | if (isErr) 24 | { 25 | errorLogTb.AppendText(log + "\r\n"); 26 | LOGGER.Error(log); 27 | } 28 | else 29 | { 30 | normalLogTb.AppendText(log + "\r\n"); 31 | LOGGER.Info(log); 32 | } 33 | } 34 | 35 | public static void AddIgnoreLog(string fileName, string sheetName, string reason) 36 | { 37 | StringBuilder sb = new StringBuilder(); 38 | sb.Append("["); 39 | sb.Append(fileName); 40 | sb.Append("]--"); 41 | sb.Append("["); 42 | sb.Append(sheetName); 43 | sb.Append("]--"); 44 | sb.Append(reason); 45 | sb.Append("--被忽略"); 46 | Add(sb.ToString(), true); 47 | } 48 | 49 | public static void AddNormalLog(string fileName, string msg) 50 | { 51 | StringBuilder sb = new StringBuilder(); 52 | sb.Append("["); 53 | sb.Append(fileName); 54 | sb.Append("]--"); 55 | sb.Append(msg); 56 | Add(sb.ToString()); 57 | } 58 | 59 | 60 | 61 | } -------------------------------------------------------------------------------- /ExcelToCode/Utils/Setting.cs: -------------------------------------------------------------------------------- 1 | using ExcelToCode.Excel; 2 | using NLog; 3 | using NLog.Config; 4 | using System.Xml; 5 | 6 | namespace ExcelToCode 7 | { 8 | public static class Setting 9 | { 10 | 11 | private static readonly NLog.Logger LOGGER = LogManager.GetCurrentClassLogger(); 12 | 13 | /// 14 | /// 普通表缓冲区大小-512KB 15 | /// 16 | public static int NormalBufferSize = 512 * 1024; 17 | 18 | /// 19 | /// 语言包缓冲区大小-5M 20 | /// 21 | public static int LanguageBufferSize = 5 * 1024 * 1024; 22 | 23 | /// 24 | /// 配置表路径 25 | /// 26 | public static string ConfigPath { private set; get; } 27 | 28 | 29 | /// 30 | /// 客户端Bin路径 31 | /// 32 | public static string ClientBinPath { private set; get; } 33 | 34 | /// 35 | /// 服务器二进制路径 36 | /// 37 | public static string ServerBinPath { private set; get; } 38 | 39 | /// 40 | /// 客户端代码路径 41 | /// 42 | public static string ClientCodePath { private set; get; } 43 | 44 | /// 45 | /// 服务器代码路径 46 | /// 47 | public static string ServerCodePath { private set; get; } 48 | 49 | public static bool Init() 50 | { 51 | LogManager.Configuration = new XmlLoggingConfiguration("Configs/NLog.config"); 52 | LOGGER.Info("Init tool config..."); 53 | 54 | if (File.Exists("Configs/config.xml")) 55 | { 56 | XmlDocument doc = new XmlDocument(); 57 | doc.Load("Configs/config.xml"); 58 | XmlElement root = doc.DocumentElement; 59 | XmlNode listNodes = root.SelectNodes("/config").Item(0); 60 | foreach (XmlNode node in listNodes) 61 | { 62 | switch (node.Name) 63 | { 64 | case "normal-buffer-size": 65 | NormalBufferSize = int.Parse(node.InnerText); 66 | break; 67 | case "lan-buffer-size": 68 | LanguageBufferSize = int.Parse(node.InnerText); 69 | break; 70 | case "config-path": 71 | ConfigPath = node.InnerText; 72 | break; 73 | case "server-code-path": 74 | ServerCodePath = node.InnerText; 75 | break; 76 | case "server-bin-path": 77 | ServerBinPath = node.InnerText; 78 | break; 79 | case "client-code-path": 80 | ClientCodePath = node.InnerText; 81 | break; 82 | case "client-bin-path": 83 | ClientBinPath = node.InnerText; 84 | break; 85 | } 86 | } 87 | return true; 88 | } 89 | else 90 | { 91 | LOGGER.Error("服务器配置文件错误或不存在,启动失败!"); 92 | return false; 93 | } 94 | } 95 | 96 | 97 | public static string GetBinPath(ExportType etype) 98 | { 99 | if (etype == ExportType.Client) 100 | { 101 | return @ClientBinPath + "/"; 102 | } 103 | else if (etype == ExportType.Server) 104 | { 105 | return @ServerBinPath + "/"; 106 | } 107 | LOGGER.Error("未知的导出类型{}", etype); 108 | return ""; 109 | } 110 | 111 | public static string GetCodePath(ExportType etype) 112 | { 113 | if (etype == ExportType.Client) 114 | { 115 | return @ClientCodePath + "/"; 116 | } 117 | else if (etype == ExportType.Server) 118 | { 119 | return @ServerCodePath + "/"; 120 | } 121 | LOGGER.Error("未知的导出类型{}", etype); 122 | return ""; 123 | } 124 | 125 | public static string GetTemplatePath(ExportType etype) 126 | { 127 | if (etype == ExportType.Client) 128 | { 129 | return @"Configs/Template/Client/"; 130 | } 131 | else if (etype == ExportType.Server) 132 | { 133 | return @"Configs/Template/Server/"; 134 | } 135 | LOGGER.Error("未知的导出类型{}", etype); 136 | return ""; 137 | } 138 | 139 | 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /ExcelToCode/Utils/StringUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace ExcelConverter.Utils 9 | { 10 | public class StringUtils 11 | { 12 | 13 | public static string Trim(string org) 14 | { 15 | return Regex.Replace(org, @"\s", ""); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ExcelToCode/Utils/TimeUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /// 4 | /// 时间戳工具类 5 | /// 6 | public class TimeUtils 7 | { 8 | private static readonly DateTime epochLocal = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local); 9 | private static readonly DateTime epochUtc = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Utc); 10 | 11 | public static long CurrentTimeMillis(bool utc = false) 12 | { 13 | return TimeMillis(DateTime.Now, utc); 14 | } 15 | 16 | /// 17 | /// 某个时间的毫秒数 18 | /// 19 | /// 20 | /// 21 | /// 22 | public static long TimeMillis(DateTime time, bool utc = false) 23 | { 24 | if (utc) 25 | return (long)(time - epochUtc).TotalMilliseconds; 26 | return (long)(time - epochLocal).TotalMilliseconds; 27 | } 28 | 29 | /// 30 | /// 毫秒转时间 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static DateTime MillisToDateTime(long time, bool utc = false) 36 | { 37 | if (utc) 38 | return epochUtc.AddMilliseconds(time); 39 | return epochLocal.AddMilliseconds(time); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /ExcelToCode/Utils/XBuffer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/ExcelToCode/Utils/XBuffer.cs -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GeekConfig 2 | Excel一键导出二进制数据及解析代码,Super Fast,支持Unity3d,IlRuntime,.Netcore , .Net Framework 3 | API简洁,使用方便,性能高 4 | 5 | ### Excel填表规则(请参考output/excel下模板进行填写) 6 | 1.第一行:CS代表这张表客户端和服务器都会导出(c:client s:server,不填代表cs) 7 | 2.第二行:字段名称,必须以t_开头(非t_开头列不会被导出) 8 | 3.第三行:数据类型,目前支持int(默认可以不填),string(text), long, textmult(多语言处理,代表这个字段会从语言表中读取真正的值),float 9 | 4.第四行:第一列为表名(主键列,一定会导出),后续的列可以通过填c,s,cs,sc来控制是否需要导出(c:client s:server,不填代表cs) 10 | 5.第五行:字段备注 11 | 6.表单名字必须以t_开头(非t_开头表单不会被导出),支持多个表单 12 | 13 | ### 支持按需加载/启动时全部加载(非线程安全) 14 | GameDataManager.Instance.LoadAll(); 15 | 建议:服务器一开始就全部加载,客户端(unity3d)单线程按需加载即可 16 | 17 | ### 按ID获取数据 18 | var bean = ConfigBean.GetBean(1020001); 19 | if(bean != null) Console.WriteLine(bean.t_string_param); 20 | 21 | ### 获取整个列表 22 | var list = ConfigBean.GetBeanList(); 23 | foreach (var item in list) 24 | Console.WriteLine(item.t_name + "-------" + item.t_skill); 25 | 26 | ### 说明 27 | Configs/config.xml: 可以对工具相关路径进行设置 28 | Configs/Template: 工程中的client和server模板是一样的,可以根据自己的需求修改 29 | ![Image text](https://github.com/leeveel/ExcelToCode/blob/main/Doc/configtool.png) 30 | -------------------------------------------------------------------------------- /Test/Base/ConfigManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Base 5 | { 6 | /// 7 | /// 8 | /// 9 | public class ConfigManager : SingletonTemplate 10 | { 11 | 12 | public string Language = "t_chinese"; 13 | 14 | public bool IsServer = true; 15 | 16 | public byte[] GetData(string fileName) 17 | { 18 | try 19 | { 20 | if(IsServer) 21 | return File.ReadAllBytes("../../data/server/" + fileName + ".bytes"); 22 | else 23 | return File.ReadAllBytes("../../data/client/" + fileName + ".bytes"); 24 | } 25 | catch(Exception e) 26 | { 27 | Console.WriteLine(e.ToString()); 28 | return null; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Test/Base/Debuger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Base 6 | { 7 | public class Debuger 8 | { 9 | public static void Err(string txt) 10 | { 11 | Console.WriteLine(txt); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Test/Base/SingletonTemplate.cs: -------------------------------------------------------------------------------- 1 | 2 | /// 3 | /// 非线程安全单件模板 4 | /// 5 | /// 6 | 7 | namespace Base 8 | { 9 | public class SingletonTemplate where T : class, new() 10 | { 11 | protected static T singleton = null; 12 | 13 | public static T Singleton 14 | { 15 | get 16 | { 17 | if (singleton == null) 18 | { 19 | singleton = new T(); 20 | } 21 | return singleton; 22 | } 23 | } 24 | 25 | public static void DestorySelf() 26 | { 27 | singleton = null; 28 | } 29 | 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Test/Program.cs: -------------------------------------------------------------------------------- 1 | using Base; 2 | using Data.Beans; 3 | using Data.Containers; 4 | using System; 5 | 6 | namespace Test 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | Console.WriteLine("-----------------start----------------"); 13 | //设置测试服务器/客户端 14 | ConfigManager.Singleton.IsServer = false; 15 | //可以在程序已启动时候把所有数据表加载到内存 16 | //也可以需要的时候再加载(未处理线程安全,所以服务器应该在启服时全部加载) 17 | //GameDataManager.Instance.LoadAll(); 18 | var bean = ConfigBean.GetBean(1020001); 19 | if(bean != null) 20 | Console.WriteLine(bean.t_string_param); 21 | 22 | var list = ConfigBean.GetBeanList(); 23 | foreach (var item in list) 24 | Console.WriteLine(item.t_name + "-------" + item.t_skill); 25 | 26 | Console.WriteLine("-----------------end----------------"); 27 | Console.ReadLine(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test/Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | false 10 | 11 | 12 | 13 | true 14 | ..\output\app\release\ 15 | 16 | 17 | 18 | ..\output\app\debug\ 19 | false 20 | true 21 | TRACE 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Test/XBuffer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/Test/XBuffer.cs -------------------------------------------------------------------------------- /Test/code/Data/Beans/t_globalBean.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Data.Containers; 5 | using Base; 6 | 7 | namespace Data.Beans 8 | { 9 | ///全局表 10 | public class t_globalBean : BaseBin 11 | { 12 | ///Id 13 | public int t_id; 14 | ///整形 15 | public int t_int_param; 16 | ///字符串 17 | public string t_string_param; 18 | 19 | public void LoadData(byte[] data, ref int offset) 20 | { 21 | t_id = XBuffer.ReadInt(data, ref offset); 22 | t_int_param = XBuffer.ReadInt(data, ref offset); 23 | t_string_param = XBuffer.ReadString(data, ref offset); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Test/code/Data/Beans/t_languageBean.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | * 语言包表 4 | */ 5 | using Data.Containers; 6 | using Base; 7 | 8 | namespace Data.Beans 9 | { 10 | public class t_languageBean : BaseBin 11 | { 12 | 13 | public int t_id; 14 | public string t_content; 15 | 16 | public void LoadData(byte[] data, ref int offset) 17 | { 18 | 19 | string useField = ConfigManager.Singleton.Language; 20 | t_id = XBuffer.ReadInt(data, ref offset); 21 | 22 | if (string.IsNullOrEmpty(t_content) && useField == "t_chinese") 23 | { 24 | t_content = XBuffer.ReadString(data, ref offset); 25 | } 26 | else 27 | { 28 | //ignore no need language 29 | short slen = XBuffer.ReadShort(data, ref offset); 30 | offset += slen; 31 | } 32 | 33 | 34 | if (string.IsNullOrEmpty(t_content) && useField == "t_chinesetraditional") 35 | { 36 | t_content = XBuffer.ReadString(data, ref offset); 37 | } 38 | else 39 | { 40 | //ignore no need language 41 | short slen = XBuffer.ReadShort(data, ref offset); 42 | offset += slen; 43 | } 44 | 45 | 46 | if (string.IsNullOrEmpty(t_content) && useField == "t_english") 47 | { 48 | t_content = XBuffer.ReadString(data, ref offset); 49 | } 50 | else 51 | { 52 | //ignore no need language 53 | short slen = XBuffer.ReadShort(data, ref offset); 54 | offset += slen; 55 | } 56 | 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Test/code/Data/Beans/t_monsterBean.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Data.Containers; 5 | using Base; 6 | 7 | namespace Data.Beans 8 | { 9 | ///怪物表 10 | public class t_monsterBean : BaseBin 11 | { 12 | ///Id 13 | public int t_id; 14 | private int m_t_name; 15 | ///名字id 16 | public string t_name 17 | { 18 | get 19 | { 20 | if(m_t_name == 0) 21 | return ""; 22 | t_languageBean lanBean = ConfigBean.GetBean(m_t_name); 23 | if (lanBean != null) 24 | return lanBean.t_content; 25 | else 26 | return m_t_name.ToString(); 27 | } 28 | } 29 | ///对应角色id 30 | public int t_monster_id; 31 | ///战斗ui类型 32 | public int t_monster_ui; 33 | ///类型 34 | public int t_monster_type; 35 | ///星级 36 | public int t_star; 37 | ///等级 38 | public int t_lv; 39 | ///头像id 40 | public int t_head; 41 | ///阵营 42 | public int t_camp; 43 | ///职业类型 44 | public int t_type; 45 | ///预制件 46 | public int t_battle_prefab; 47 | ///预制件缩放 48 | public int t_scale; 49 | ///技能id 50 | public string t_skill; 51 | ///属性加成 52 | public int t_att; 53 | 54 | public void LoadData(byte[] data, ref int offset) 55 | { 56 | t_id = XBuffer.ReadInt(data, ref offset); 57 | m_t_name = XBuffer.ReadInt(data, ref offset); 58 | t_monster_id = XBuffer.ReadInt(data, ref offset); 59 | t_monster_ui = XBuffer.ReadInt(data, ref offset); 60 | t_monster_type = XBuffer.ReadInt(data, ref offset); 61 | t_star = XBuffer.ReadInt(data, ref offset); 62 | t_lv = XBuffer.ReadInt(data, ref offset); 63 | t_head = XBuffer.ReadInt(data, ref offset); 64 | t_camp = XBuffer.ReadInt(data, ref offset); 65 | t_type = XBuffer.ReadInt(data, ref offset); 66 | t_battle_prefab = XBuffer.ReadInt(data, ref offset); 67 | t_scale = XBuffer.ReadInt(data, ref offset); 68 | t_skill = XBuffer.ReadString(data, ref offset); 69 | t_att = XBuffer.ReadInt(data, ref offset); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Test/code/Data/Containers/t_globalContainer.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it server 3 | * 4 | * 全局表 5 | */ 6 | 7 | using Base; 8 | using System; 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using System.IO; 12 | using Data.Beans; 13 | 14 | namespace Data.Containers 15 | { 16 | public class t_globalContainer : BaseContainer 17 | { 18 | private List list = new List(); 19 | private Dictionary map = new Dictionary(); 20 | 21 | //public override List getList() 22 | public override IList getList() 23 | { 24 | return list; 25 | } 26 | 27 | //public override Dictionary getMap() 28 | public override IDictionary getMap() 29 | { 30 | return map; 31 | } 32 | 33 | public Type BinType = typeof(t_globalBean); 34 | 35 | public override void loadDataFromBin() 36 | { 37 | map.Clear(); 38 | list.Clear(); 39 | Loaded = true; 40 | 41 | byte[] data = ConfigManager.Singleton.GetData("t_globalBean"); 42 | if(data != null) 43 | { 44 | try 45 | { 46 | int offset = 0; 47 | //filed count��int��+ field type��byte��(0:int 1:long 2:string 3:float) 48 | offset = 42; 49 | while (data.Length > offset) 50 | { 51 | t_globalBean bean = new t_globalBean(); 52 | bean.LoadData(data, ref offset); 53 | list.Add(bean); 54 | if(!map.ContainsKey(bean.t_id)) 55 | map.Add(bean.t_id, bean); 56 | else 57 | Debuger.Err("Exist duplicate Key: " + bean.t_id + " t_globalBean"); 58 | } 59 | } 60 | catch (Exception ex) 61 | { 62 | Debuger.Err("import data error: t_globalBean >>" + ex.ToString()); 63 | } 64 | } 65 | else 66 | { 67 | Debuger.Err("can not find conf data: t_globalBean.bytes"); 68 | } 69 | } 70 | 71 | } 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /Test/code/Data/Containers/t_languageContainer.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it server 3 | * 4 | * 语言包表 5 | */ 6 | 7 | using Base; 8 | using System; 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using System.IO; 12 | using Data.Beans; 13 | 14 | namespace Data.Containers 15 | { 16 | public class t_languageContainer : BaseContainer 17 | { 18 | private List list = new List(); 19 | private Dictionary map = new Dictionary(); 20 | 21 | //public override List getList() 22 | public override IList getList() 23 | { 24 | return list; 25 | } 26 | 27 | //public override Dictionary getMap() 28 | public override IDictionary getMap() 29 | { 30 | return map; 31 | } 32 | 33 | public Type BinType = typeof(t_languageBean); 34 | 35 | public override void loadDataFromBin() 36 | { 37 | map.Clear(); 38 | list.Clear(); 39 | Loaded = true; 40 | 41 | byte[] data = ConfigManager.Singleton.GetData("t_languageBean"); 42 | if(data != null) 43 | { 44 | try 45 | { 46 | int offset = 0; 47 | //filed count��int��+ field type��byte��(0:int 1:long 2:string 3:float) 48 | offset = 58; 49 | while (data.Length > offset) 50 | { 51 | t_languageBean bean = new t_languageBean(); 52 | bean.LoadData(data, ref offset); 53 | list.Add(bean); 54 | if(!map.ContainsKey(bean.t_id)) 55 | map.Add(bean.t_id, bean); 56 | else 57 | Debuger.Err("Exist duplicate Key: " + bean.t_id + " t_languageBean"); 58 | } 59 | } 60 | catch (Exception ex) 61 | { 62 | Debuger.Err("import data error: t_languageBean >>" + ex.ToString()); 63 | } 64 | } 65 | else 66 | { 67 | Debuger.Err("can not find conf data: t_languageBean.bytes"); 68 | } 69 | } 70 | 71 | } 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /Test/code/Data/Containers/t_monsterContainer.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it server 3 | * 4 | * 怪物表 5 | */ 6 | 7 | using Base; 8 | using System; 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using System.IO; 12 | using Data.Beans; 13 | 14 | namespace Data.Containers 15 | { 16 | public class t_monsterContainer : BaseContainer 17 | { 18 | private List list = new List(); 19 | private Dictionary map = new Dictionary(); 20 | 21 | //public override List getList() 22 | public override IList getList() 23 | { 24 | return list; 25 | } 26 | 27 | //public override Dictionary getMap() 28 | public override IDictionary getMap() 29 | { 30 | return map; 31 | } 32 | 33 | public Type BinType = typeof(t_monsterBean); 34 | 35 | public override void loadDataFromBin() 36 | { 37 | map.Clear(); 38 | list.Clear(); 39 | Loaded = true; 40 | 41 | byte[] data = ConfigManager.Singleton.GetData("t_monsterBean"); 42 | if(data != null) 43 | { 44 | try 45 | { 46 | int offset = 0; 47 | //filed count��int��+ field type��byte��(0:int 1:long 2:string 3:float) 48 | offset = 156; 49 | while (data.Length > offset) 50 | { 51 | t_monsterBean bean = new t_monsterBean(); 52 | bean.LoadData(data, ref offset); 53 | list.Add(bean); 54 | if(!map.ContainsKey(bean.t_id)) 55 | map.Add(bean.t_id, bean); 56 | else 57 | Debuger.Err("Exist duplicate Key: " + bean.t_id + " t_monsterBean"); 58 | } 59 | } 60 | catch (Exception ex) 61 | { 62 | Debuger.Err("import data error: t_monsterBean >>" + ex.ToString()); 63 | } 64 | } 65 | else 66 | { 67 | Debuger.Err("can not find conf data: t_monsterBean.bytes"); 68 | } 69 | } 70 | 71 | } 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /Test/code/GameDataManager.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Auto generated, do not edit it client 3 | */ 4 | using Base; 5 | using System; 6 | using Data.Beans; 7 | using Data.Containers; 8 | using System.Collections; 9 | using System.Collections.Generic; 10 | 11 | namespace Data.Containers 12 | { 13 | public class GameDataManager 14 | { 15 | public static readonly GameDataManager Instance = new GameDataManager(); 16 | public t_languageContainer t_languageContainer = new t_languageContainer(); 17 | public t_globalContainer t_globalContainer = new t_globalContainer(); 18 | public t_monsterContainer t_monsterContainer = new t_monsterContainer(); 19 | //@%@%@ 20 | private GameDataManager() 21 | { 22 | t_containerMap.Add(t_languageContainer.BinType, t_languageContainer); 23 | t_containerMap.Add(t_globalContainer.BinType, t_globalContainer); 24 | t_containerMap.Add(t_monsterContainer.BinType, t_monsterContainer); 25 | //@#@#@ 26 | } 27 | 28 | public void LoadAll(bool forceReload = false) 29 | { 30 | LoadOneBean(t_languageContainer.BinType, forceReload); 31 | LoadOneBean(t_globalContainer.BinType, forceReload); 32 | LoadOneBean(t_monsterContainer.BinType, forceReload); 33 | //@*@*@ 34 | } 35 | 36 | //bin -- container dictionary 37 | private Dictionary t_containerMap = new Dictionary(); 38 | 39 | public T GetBin(K key, bool ignoreErrLog) where T : BaseBin 40 | { 41 | Type t = typeof(T); 42 | LoadOneBean(t); 43 | if(t_containerMap.ContainsKey(t)) 44 | { 45 | var t_container = t_containerMap[t]; 46 | Dictionary map = t_container.getMap() as Dictionary; 47 | if(map != null && map.ContainsKey(key)) 48 | return map[key]; 49 | //UnityEngine.Debug.LogError("T,K get > " + t.Name + "," + typeof(K).Name + " should be > " + t_container.getMap()); 50 | } 51 | if(false == ignoreErrLog) 52 | Debuger.Err("can not find Bin > " + t.Name + " id > " + key); 53 | return null; 54 | } 55 | 56 | public List GetBinList() where T : BaseBin 57 | { 58 | Type t = typeof(T); 59 | LoadOneBean(t); 60 | if(t_containerMap.ContainsKey(t)) 61 | { 62 | var t_container = t_containerMap[t]; 63 | List list = t_container.getList() as List; 64 | if(list != null) 65 | return list; 66 | Debuger.Err("can not find Bin > " + t.Name); 67 | } 68 | Debuger.Err("can not find Bin > " + t.Name); 69 | return null; 70 | } 71 | 72 | public Dictionary GetBinMap() where T : BaseBin 73 | { 74 | Type t = typeof(T); 75 | LoadOneBean(t); 76 | if(t_containerMap.ContainsKey(t)) 77 | { 78 | var t_container = t_containerMap[t]; 79 | Dictionary map = t_container.getMap() as Dictionary; 80 | if(map != null) 81 | return map; 82 | Debuger.Err("T,K get > " + t.Name + "," + typeof(K).Name + " should be > " + t_container.getMap()); 83 | } 84 | return null; 85 | } 86 | 87 | public void LoadOneBean(bool forceReload = false) where T : BaseBin 88 | { 89 | Type t = typeof(T); 90 | LoadOneBean(t, forceReload); 91 | } 92 | 93 | public void LoadOneBean(Type t, bool forceReload = false) 94 | { 95 | if (t_containerMap.ContainsKey(t)) 96 | { 97 | if (!t_containerMap[t].Loaded || forceReload) 98 | { 99 | t_containerMap[t].loadDataFromBin(); 100 | } 101 | } 102 | } 103 | } 104 | 105 | public class BaseContainer 106 | { 107 | public bool Loaded { get; protected set; } 108 | public virtual IList getList() 109 | { 110 | return null; 111 | } 112 | 113 | public virtual IDictionary getMap() 114 | { 115 | return null; 116 | } 117 | 118 | public virtual void loadDataFromBin() 119 | { 120 | 121 | } 122 | } 123 | 124 | public class BaseBin 125 | { 126 | } 127 | } 128 | 129 | public class ConfigBean 130 | { 131 | public static bool IsServer; 132 | /// 133 | ///T -----> Bean 134 | ///K -----> id type (int/string) 135 | /// 136 | public static T GetBean(K id, bool ignoreErrLog = false) where T : BaseBin 137 | { 138 | return GameDataManager.Instance.GetBin(id, ignoreErrLog); 139 | } 140 | 141 | /// 142 | /// Get Table Data By List 143 | /// 144 | public static List GetBeanList() where T : BaseBin 145 | { 146 | return GameDataManager.Instance.GetBinList(); 147 | } 148 | 149 | /// 150 | /// Get Table Data By Map 151 | /// 152 | public static Dictionary GetBeanMap() where T : BaseBin 153 | { 154 | return GameDataManager.Instance.GetBinMap(); 155 | } 156 | } 157 | 158 | public static class ConfigExtension 159 | { 160 | public static string GetItsLanaugeStr(this int id) 161 | { 162 | var bean = ConfigBean.GetBean(id); 163 | if(bean != null) 164 | return bean.t_content; 165 | return id.ToString(); 166 | } 167 | 168 | public static string GetItsGlobalStr(this int id) 169 | { 170 | var bean = ConfigBean.GetBean(id); 171 | if(bean != null) 172 | return bean.t_string_param; 173 | return ""; 174 | } 175 | 176 | public static int GetItsGlobalInt(this int id) 177 | { 178 | var bean = ConfigBean.GetBean(id); 179 | if(bean != null) 180 | return bean.t_int_param; 181 | return 0; 182 | } 183 | } -------------------------------------------------------------------------------- /output/data/client/t_globalBean.bytes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/data/client/t_globalBean.bytes -------------------------------------------------------------------------------- /output/data/client/t_languageBean.bytes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/data/client/t_languageBean.bytes -------------------------------------------------------------------------------- /output/data/client/t_monsterBean.bytes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/data/client/t_monsterBean.bytes -------------------------------------------------------------------------------- /output/data/server/t_globalBean.bytes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/data/server/t_globalBean.bytes -------------------------------------------------------------------------------- /output/data/server/t_languageBean.bytes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/data/server/t_languageBean.bytes -------------------------------------------------------------------------------- /output/data/server/t_monsterBean.bytes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/data/server/t_monsterBean.bytes -------------------------------------------------------------------------------- /output/excel/0 语言包.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/excel/0 语言包.xlsx -------------------------------------------------------------------------------- /output/excel/1 全局表.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/excel/1 全局表.xlsx -------------------------------------------------------------------------------- /output/excel/6 怪物表.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leeveel/GeekConfig/7d3e2d7eae9b95b0db7a2b3a9291dd08ecfb65fa/output/excel/6 怪物表.xlsx --------------------------------------------------------------------------------