├── Excel2Unity
├── .idea
│ ├── Excel2Unity.iml
│ ├── encodings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
├── Config.py
├── ConfigDataGen.py
├── Excel
│ ├── Test1
│ │ └── Test1.xlsx
│ ├── Test2
│ │ └── Test2.xlsx
│ └── Test3
│ │ └── Test3.xlsx
├── Excel2Unity.py
├── FieldFormat.py
├── MacRun.sh
├── UnityCodeGen.py
├── WinRun.bat
└── main.py
├── ExcelTest
├── Assets
│ ├── Scenes.meta
│ ├── Scenes
│ │ ├── TestExcel.unity
│ │ └── TestExcel.unity.meta
│ ├── Scripts.meta
│ ├── Scripts
│ │ ├── Config.meta
│ │ ├── Config
│ │ │ ├── ConfigManager.cs
│ │ │ ├── ConfigManager.cs.meta
│ │ │ ├── Test1.meta
│ │ │ ├── Test1
│ │ │ │ ├── Test1.cs
│ │ │ │ └── Test1.cs.meta
│ │ │ ├── Test2.meta
│ │ │ ├── Test2
│ │ │ │ ├── Test2.cs
│ │ │ │ └── Test2.cs.meta
│ │ │ ├── Test3.meta
│ │ │ └── Test3
│ │ │ │ ├── Test3.cs
│ │ │ │ └── Test3.cs.meta
│ │ ├── Core.meta
│ │ ├── Core
│ │ │ ├── Config.meta
│ │ │ ├── Config
│ │ │ │ ├── SheetGenCommonFunc.cs
│ │ │ │ └── SheetGenCommonFunc.cs.meta
│ │ │ ├── DynamicPacket.cs
│ │ │ ├── DynamicPacket.cs.meta
│ │ │ ├── IDynamicData.cs
│ │ │ └── IDynamicData.cs.meta
│ │ ├── TestExcel.cs
│ │ └── TestExcel.cs.meta
│ ├── StreamingAssets.meta
│ └── StreamingAssets
│ │ ├── Config.meta
│ │ └── Config
│ │ ├── Config.data
│ │ └── Config.data.meta
└── ProjectSettings
│ ├── AudioManager.asset
│ ├── ClusterInputManager.asset
│ ├── DynamicsManager.asset
│ ├── EditorBuildSettings.asset
│ ├── EditorSettings.asset
│ ├── GraphicsSettings.asset
│ ├── InputManager.asset
│ ├── NavMeshAreas.asset
│ ├── NetworkManager.asset
│ ├── Physics2DSettings.asset
│ ├── ProjectSettings.asset
│ ├── ProjectVersion.txt
│ ├── QualitySettings.asset
│ ├── TagManager.asset
│ ├── TimeManager.asset
│ └── UnityConnectSettings.asset
├── README.md
└── Snapshots
└── Doc1.bmp
/Excel2Unity/.idea/Excel2Unity.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Excel2Unity/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Excel2Unity/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Excel2Unity/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Excel2Unity/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
33 |
34 |
35 |
36 | utf-8
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 | 1544935881957
140 |
141 |
142 | 1544935881957
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
--------------------------------------------------------------------------------
/Excel2Unity/Config.py:
--------------------------------------------------------------------------------
1 |
2 | # --------------------------------Excel--------------------------------
3 | # Excel文件目录
4 | EXCEL_DIR = "./Excel"
5 |
6 | # excel文件的后缀
7 | EXCEL_EXT = ".xlsx"
8 |
9 | # unity表格字段的过滤
10 | UNITY_TABLE_FIELD_FILTER = ["cs", "c", "CS", "C"]
11 |
12 | # 服务器表格字段的过滤
13 | SERVER_TABLE_FIELD_FILTER = ["cs", "s", "CS", "S"]
14 |
15 | # key的修饰符名字
16 | KEY_MODIFIER_NAME = "KEY"
17 |
18 | # 数据文件名
19 | DataFileName = "Config.data"
20 |
21 | # --------------------------------Unity--------------------------------
22 |
23 | # 数据生成路径
24 | UnityDataDir = "./../ExcelTest/Assets/StreamingAssets/Config/"
25 |
26 | # 代码生成路径
27 | UnityCodeDir = "./../ExcelTest/Assets/Scripts/Config/"
28 |
--------------------------------------------------------------------------------
/Excel2Unity/ConfigDataGen.py:
--------------------------------------------------------------------------------
1 |
2 | import os
3 | import struct
4 | from FieldFormat import FieldFormat
5 | from Config import DataFileName
6 |
7 | class ConfigDataGen:
8 |
9 | # 保存文件
10 | @staticmethod
11 | def Save(inbytes, datapath):
12 | datapath += DataFileName
13 |
14 | filedir = os.path.dirname(datapath)
15 | if os.path.exists(filedir) == False:
16 | os.makedirs(filedir)
17 |
18 | byteslen = len(inbytes)
19 | savebytes = struct.pack('i', byteslen)
20 | savebytes += inbytes
21 | file = open(datapath, 'wb+')
22 | file.write(savebytes)
23 | file.close()
24 |
25 | @staticmethod
26 | def Encode2Bytes(format, val):
27 |
28 | if format == "i":
29 | bytes = struct.pack(format, int(val))
30 | elif format == "f":
31 | bytes = struct.pack(format, float(val))
32 | elif format == "?":
33 | bytes = struct.pack(format, bool(val))
34 | elif format == "s":
35 | newval = val.encode()
36 | vallen = len(newval)
37 | lenbyte = struct.pack("i", vallen)
38 |
39 | strformat = str(vallen) + format
40 | valbyte = struct.pack(strformat, newval)
41 |
42 | bytes = lenbyte + valbyte
43 |
44 | return bytes
45 |
46 | # 文件生成函数
47 | @staticmethod
48 | def Process(fields, table):
49 |
50 | allbytes = bytes()
51 |
52 | count = 0
53 | for row in range(5, table.nrows):
54 | count += 1
55 |
56 | for col in range(table.ncols):
57 | if col in fields:
58 | val = table.cell(row, col).value
59 | type = table.cell(2, col).value
60 | format = FieldFormat.Type2format[type][0]
61 | allbytes += ConfigDataGen.Encode2Bytes(format, val)
62 |
63 | outbytes = struct.pack('i', count)
64 | outbytes += allbytes
65 |
66 | return outbytes
67 |
68 |
--------------------------------------------------------------------------------
/Excel2Unity/Excel/Test1/Test1.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieliujian/Excel2Unity/9821e0799558d81179b41d517996455f53803a53/Excel2Unity/Excel/Test1/Test1.xlsx
--------------------------------------------------------------------------------
/Excel2Unity/Excel/Test2/Test2.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieliujian/Excel2Unity/9821e0799558d81179b41d517996455f53803a53/Excel2Unity/Excel/Test2/Test2.xlsx
--------------------------------------------------------------------------------
/Excel2Unity/Excel/Test3/Test3.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xieliujian/Excel2Unity/9821e0799558d81179b41d517996455f53803a53/Excel2Unity/Excel/Test3/Test3.xlsx
--------------------------------------------------------------------------------
/Excel2Unity/Excel2Unity.py:
--------------------------------------------------------------------------------
1 |
2 | import os
3 | import xlrd
4 | from Config import EXCEL_DIR
5 | from Config import EXCEL_EXT
6 | from Config import UNITY_TABLE_FIELD_FILTER
7 | from Config import UnityDataDir
8 | from ConfigDataGen import ConfigDataGen
9 | from UnityCodeGen import UnityCodeGen
10 |
11 | class Excel2Unity:
12 | # 构造函数
13 | def __init__(self):
14 | self.mExcelFiles = [] # 所有的excel文件
15 |
16 | # 外部处理函数
17 | def Process(self):
18 | self.RecursiveSearchExcel(EXCEL_DIR)
19 | self.ProcessExcelExportUnity()
20 |
21 | # 递归查找文件
22 | def RecursiveSearchExcel(self, path):
23 | for pathdir in os.listdir(path): # 遍历当前目录
24 | fullpath = os.path.join(path, pathdir)
25 |
26 | if os.path.isdir(fullpath):
27 | self.RecursiveSearchExcel(fullpath)
28 | elif os.path.isfile(fullpath):
29 | if os.path.splitext(fullpath)[1] == EXCEL_EXT:
30 | self.mExcelFiles.append(fullpath)
31 |
32 | # 处理excel文件
33 | def ProcessExcelExportUnity(self):
34 |
35 | allbytesdata = bytes()
36 |
37 | # 处理每个文件
38 | for filename in self.mExcelFiles:
39 | data = xlrd.open_workbook(filename)
40 | table = data.sheets()[0]
41 | fields = self.FilterFieldData(table, UNITY_TABLE_FIELD_FILTER)
42 |
43 | # 数据
44 | cfgbytes = ConfigDataGen.Process(fields, table)
45 | allbytesdata += cfgbytes
46 |
47 | # 代码
48 | UnityCodeGen.Process(filename, fields, table)
49 |
50 | # 后处理
51 | ConfigDataGen.Save(allbytesdata, UnityDataDir)
52 | UnityCodeGen.GenConfigMangerCode(self.mExcelFiles)
53 |
54 | # 筛选字段数据
55 | def FilterFieldData(self, table, fieldfilter):
56 | fields = []
57 | for index in range(table.ncols):
58 | row = table.cell(1, index).value
59 | for field in fieldfilter:
60 | if row == field:
61 | fields.append(index)
62 |
63 | return fields
--------------------------------------------------------------------------------
/Excel2Unity/FieldFormat.py:
--------------------------------------------------------------------------------
1 |
2 | class FieldFormat:
3 | Type2format = {
4 | "int": ("i", "int", "packet.PackReadInt32()"),
5 | "float": ("f", "float", "packet.PackReadFloat()"),
6 | "bool": ("?", "bool", "packet.PackReadBoolean()"),
7 | "string": ("s", "string", "packet.PackReadString()"),
8 |
9 | "list[int]": ("s", "List", "SheetGenCommonFunc.GetListInt(packet.PackReadString())"),
10 | "list[float]": ("s", "List", "SheetGenCommonFunc.GetListFloat(packet.PackReadString())"),
11 | "list[string]": ("s", "List", "SheetGenCommonFunc.GetListString(packet.PackReadString())"),
12 |
13 | "map[int|int]": ("s", "Dictionary", "SheetGenCommonFunc.GetDictIntInt(packet.PackReadString())"),
14 | "map[int|float]": ("s", "Dictionary", "SheetGenCommonFunc.GetDictIntFloat(packet.PackReadString())"),
15 | "map[int|string]": ("s", "Dictionary", "SheetGenCommonFunc.GetDictIntString(packet.PackReadString())"),
16 |
17 | "map[string|int]": ("s", "Dictionary", "SheetGenCommonFunc.GetDictStringInt(packet.PackReadString())"),
18 | "map[string|float]": ("s", "Dictionary", "SheetGenCommonFunc.GetDictStringFloat(packet.PackReadString())"),
19 | "map[string|string]": ("s", "Dictionary", "SheetGenCommonFunc.GetDictStringString(packet.PackReadString())")
20 | }
--------------------------------------------------------------------------------
/Excel2Unity/MacRun.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | cd /Users/xieliujian/Desktop/xieliujian/python/excel2unity/trunk/
3 | python3 main.py
4 |
--------------------------------------------------------------------------------
/Excel2Unity/UnityCodeGen.py:
--------------------------------------------------------------------------------
1 |
2 | import os
3 | from FieldFormat import FieldFormat
4 | from Config import KEY_MODIFIER_NAME
5 | from Config import EXCEL_DIR
6 | from Config import UnityCodeDir
7 |
8 | class UnityCodeGen:
9 |
10 | @staticmethod
11 | def Tab(count):
12 | return " " * count;
13 |
14 | # 代码生成函数
15 | @staticmethod
16 | def Process(filepath, fields, table):
17 |
18 | # -----------------------table cfg class-----------------------
19 | filecontent = "\n"
20 | filecontent += "//-----------------------------------------------\n"
21 | filecontent += "// 生成代码不要修改\n"
22 | filecontent += "//-----------------------------------------------\n"
23 | filecontent += "\n"
24 | filecontent += "using System.Collections.Generic;\n"
25 | filecontent += "using System.IO;\n"
26 | filecontent += "using System.Text;\n"
27 | filecontent += "using UnityEngine;\n"
28 | filecontent += "\n"
29 |
30 | tablebasename = os.path.basename(filepath)
31 | tablebasename = tablebasename.split(".")[0]
32 | tableclassname = tablebasename + "Cfg"
33 | filecontent += "public class " + tableclassname + "\n"
34 | filecontent += "{\n"
35 |
36 | for index in fields:
37 | fielddesc = table.cell(0, index).value
38 | fieldtype = table.cell(2, index).value
39 | fieldname = table.cell(3, index).value
40 | fieldvar = FieldFormat.Type2format[fieldtype][1]
41 | filecontent += UnityCodeGen.Tab(1) + "public " + fieldvar + " " + fieldname + ";"
42 | filecontent += UnityCodeGen.Tab(1) + "// " + fielddesc + "\n"
43 |
44 | # Deserialize函数
45 | filecontent += "\n"
46 | filecontent += UnityCodeGen.Tab(1) + "public void Deserialize (DynamicPacket packet)\n"
47 | filecontent += UnityCodeGen.Tab(1) + "{\n"
48 |
49 | for index in fields:
50 | fielddesc = table.cell(0, index).value
51 | fieldtype = table.cell(2, index).value
52 | fieldname = table.cell(3, index).value
53 | fieldfunc = FieldFormat.Type2format[fieldtype][2]
54 | filecontent += UnityCodeGen.Tab(2) + fieldname + " = " + fieldfunc + ";\n"
55 |
56 | filecontent += UnityCodeGen.Tab(1) + "}\n"
57 | filecontent += "}\n"
58 |
59 | # -----------------------table cfg manager class-----------------------
60 | filecontent += "\n"
61 | tableclassmgrname = tablebasename + "CfgMgr"
62 | filecontent += "public class " + tableclassmgrname + "\n"
63 | filecontent += "{\n"
64 |
65 | filecontent += UnityCodeGen.Tab(1) + "private static " + tableclassmgrname + " mInstance;\n"
66 | filecontent += UnityCodeGen.Tab(1) + "\n"
67 | filecontent += UnityCodeGen.Tab(1) + "public static " + tableclassmgrname + " Instance\n"
68 | filecontent += UnityCodeGen.Tab(1) + "{\n"
69 | filecontent += UnityCodeGen.Tab(2) + "get\n"
70 | filecontent += UnityCodeGen.Tab(2) + "{\n"
71 | filecontent += UnityCodeGen.Tab(3) + "if (mInstance == null)\n"
72 | filecontent += UnityCodeGen.Tab(3) + "{\n"
73 | filecontent += UnityCodeGen.Tab(4) + "mInstance = new " + tableclassmgrname + "();\n"
74 | filecontent += UnityCodeGen.Tab(3) + "}\n"
75 | filecontent += UnityCodeGen.Tab(3) + "\n"
76 | filecontent += UnityCodeGen.Tab(3) + "return mInstance;\n"
77 | filecontent += UnityCodeGen.Tab(2) + "}\n"
78 | filecontent += UnityCodeGen.Tab(1) + "}\n"
79 |
80 | # 获得keylist
81 | keylist = []
82 | for index in fields:
83 | value = table.cell(4, index).value
84 | if value == KEY_MODIFIER_NAME:
85 | keylist.append(index)
86 |
87 | # 根据keylist判断
88 | keylen = keylist.__len__()
89 | uselist = (keylen != 1)
90 | filecontent += "\n"
91 | if uselist:
92 | filecontent += UnityCodeGen.Tab(1) + "private List<{0}> mList = new List<{0}>();\n".format(tableclassname)
93 | else:
94 | fieldtype = table.cell(2, keylist[0]).value
95 | keytype = FieldFormat.Type2format[fieldtype][1]
96 | filecontent += UnityCodeGen.Tab(1) + "private Dictionary<{0}, {1}> mDict = new Dictionary<{0}, {1}>();\n".format(keytype, tableclassname)
97 |
98 | filecontent += UnityCodeGen.Tab(1) + "\n"
99 | if uselist:
100 | filecontent += UnityCodeGen.Tab(1) + "public List<{0}> List\n".format(tableclassname)
101 | else:
102 | filecontent += UnityCodeGen.Tab(1) + "public Dictionary<{0}, {1}> Dict\n".format(keytype, tableclassname)
103 | filecontent += UnityCodeGen.Tab(1) + "{\n"
104 | if uselist:
105 | filecontent += UnityCodeGen.Tab(2) + "get {return mList;}\n"
106 | else:
107 | filecontent += UnityCodeGen.Tab(2) + "get {return mDict;}\n"
108 | filecontent += UnityCodeGen.Tab(1) + "}\n"
109 |
110 | # Deserialize函数
111 | filecontent += "\n"
112 | filecontent += UnityCodeGen.Tab(1) + "public void Deserialize (DynamicPacket packet)\n"
113 | filecontent += UnityCodeGen.Tab(1) + "{\n"
114 | filecontent += UnityCodeGen.Tab(2) + "int num = (int)packet.PackReadInt32();\n"
115 | filecontent += UnityCodeGen.Tab(2) + "for (int i = 0; i < num; i++)\n"
116 | filecontent += UnityCodeGen.Tab(2) + "{\n"
117 | filecontent += UnityCodeGen.Tab(3) + tableclassname + " item = new " + tableclassname + "();\n"
118 | filecontent += UnityCodeGen.Tab(3) + "item.Deserialize(packet);\n"
119 | if uselist:
120 | filecontent += UnityCodeGen.Tab(3) + "mList.Add(item);\n"
121 | else:
122 | keyname = table.cell(3, keylist[0]).value
123 | filecontent += UnityCodeGen.Tab(3) + "if (mDict.ContainsKey(item.{0}))\n".format(keyname)
124 | filecontent += UnityCodeGen.Tab(3) + "{\n"
125 | filecontent += UnityCodeGen.Tab(4) + "mDict[item.{0}] = item;\n".format(keyname)
126 | filecontent += UnityCodeGen.Tab(3) + "}\n"
127 | filecontent += UnityCodeGen.Tab(3) + "else\n"
128 | filecontent += UnityCodeGen.Tab(3) + "{\n"
129 | filecontent += UnityCodeGen.Tab(4) + "mDict.Add(item.{0}, item);\n".format(keyname)
130 | filecontent += UnityCodeGen.Tab(3) + "}\n"
131 | filecontent += UnityCodeGen.Tab(2) + "}\n"
132 | filecontent += UnityCodeGen.Tab(1) + "}\n"
133 |
134 | # GetData函数
135 | if keylen == 1: # 有一个key值使用dict取值
136 | fieldtype = table.cell(2, keylist[0]).value
137 | keytype = FieldFormat.Type2format[fieldtype][1]
138 | keyname = table.cell(3, keylist[0]).value
139 | filecontent += UnityCodeGen.Tab(1) + "\n"
140 | filecontent += UnityCodeGen.Tab(1) + "public {0} GetDataBy{1}({2} {3})\n".format(tableclassname, keyname, keytype, keyname.lower())
141 | filecontent += UnityCodeGen.Tab(1) + "{\n"
142 | filecontent += UnityCodeGen.Tab(2) + "if(mDict.ContainsKey({0}))\n".format(keyname.lower())
143 | filecontent += UnityCodeGen.Tab(2) + "{\n"
144 | filecontent += UnityCodeGen.Tab(3) + "return mDict[{0}];\n".format(keyname.lower())
145 | filecontent += UnityCodeGen.Tab(2) + "}\n"
146 | filecontent += UnityCodeGen.Tab(2) + "\n"
147 | filecontent += UnityCodeGen.Tab(2) + "return null;\n"
148 | filecontent += UnityCodeGen.Tab(1) + "}\n"
149 | elif keylen > 1: # 有多个key值
150 | filecontent += UnityCodeGen.Tab(1) + "\n"
151 | filecontent += UnityCodeGen.Tab(1) + "public " + tableclassname + " GetDataBy"
152 |
153 | keycount = 0
154 | for keyindex in keylist:
155 | keyval = table.cell(3, keyindex).value
156 | filecontent += keyval
157 | if keycount < (keylen - 1):
158 | filecontent += "And"
159 | keycount += 1
160 |
161 | filecontent += "("
162 |
163 | keycount = 0
164 | for keyindex in keylist:
165 | keytype = table.cell(2, keyindex).value
166 | keytype = FieldFormat.Type2format[keytype][1]
167 | keyval = table.cell(3, keyindex).value
168 | keyval = keyval.lower()
169 | filecontent += keytype + " " + keyval
170 | if keycount < (keylen - 1):
171 | filecontent += ", "
172 | keycount += 1
173 | filecontent += ")\n"
174 |
175 | filecontent += UnityCodeGen.Tab(1) + "{\n"
176 | filecontent += UnityCodeGen.Tab(2) + "foreach (" + tableclassname + " data in mList)\n"
177 | filecontent += UnityCodeGen.Tab(2) + "{\n"
178 |
179 | filecontent += UnityCodeGen.Tab(3) + "if ("
180 | keycount = 0
181 | for keyindex in keylist:
182 | keyval1 = table.cell(3, keyindex).value
183 | keyval2 = keyval1.lower()
184 | filecontent += "data." + keyval1 + " == " + keyval2
185 | if keycount < (keylen - 1):
186 | filecontent += " && "
187 | keycount += 1
188 | filecontent += ")\n"
189 |
190 | filecontent += UnityCodeGen.Tab(3) + "{\n"
191 | filecontent += UnityCodeGen.Tab(4) + "return data;\n"
192 | filecontent += UnityCodeGen.Tab(3) + "}\n"
193 | filecontent += UnityCodeGen.Tab(2) + "}\n"
194 | filecontent += UnityCodeGen.Tab(2) + "\n"
195 | filecontent += UnityCodeGen.Tab(2) + "return null;\n"
196 | filecontent += UnityCodeGen.Tab(1) + "}\n"
197 |
198 | filecontent += "}\n"
199 |
200 | # 保存
201 | path = filepath.replace(EXCEL_DIR, "")
202 | path = UnityCodeDir + path
203 | path = os.path.splitext(path)[0]
204 | path = path + ".cs"
205 |
206 | # 生成文件目录, 不重复创建目录
207 | filedir = os.path.dirname(path)
208 | if os.path.exists(filedir) == False:
209 | os.makedirs(filedir)
210 |
211 | file = open(path, "wb")
212 | file.write(filecontent.encode())
213 | file.close()
214 |
215 | # 生成配置管理类
216 | @staticmethod
217 | def GenConfigMangerCode(files):
218 | path = UnityCodeDir + "ConfigManager.cs"
219 |
220 | filecontent = "\n"
221 | filecontent += "//-----------------------------------------------\n"
222 | filecontent += "// 生成代码不要修改\n"
223 | filecontent += "//-----------------------------------------------\n"
224 | filecontent += "\n"
225 | filecontent += "using System.Collections;\n"
226 | filecontent += "using System.Collections.Generic;\n"
227 | filecontent += "using UnityEngine;\n"
228 | filecontent += "using System.IO;\n"
229 | filecontent += "\n"
230 | filecontent += "public class ConfigManager\n"
231 | filecontent += "{\n"
232 |
233 | # Deserialize函数
234 | filecontent += UnityCodeGen.Tab(1) + "private static void Deserialize(DynamicPacket dynamicPacket)\n"
235 | filecontent += UnityCodeGen.Tab(1) + "{\n"
236 | for file in files:
237 | tablebasename = os.path.basename(file)
238 | tablebasename = tablebasename.split(".")[0]
239 | filecontent += UnityCodeGen.Tab(2) + tablebasename + "CfgMgr.Instance.Deserialize(dynamicPacket);\n"
240 | filecontent += UnityCodeGen.Tab(1) + "}\n"
241 |
242 | # LoadCsv函数
243 | filecontent += UnityCodeGen.Tab(1) + "\n"
244 | filecontent += UnityCodeGen.Tab(1) + "public static void LoadConfig(string cfgdatapath)\n"
245 | filecontent += UnityCodeGen.Tab(1) + "{\n"
246 | filecontent += UnityCodeGen.Tab(2) + "FileStream fileStream = new FileStream(cfgdatapath, FileMode.Open, FileAccess.Read);\n"
247 | filecontent += UnityCodeGen.Tab(2) + "BinaryReader binaryReader = new BinaryReader(fileStream);\n"
248 | filecontent += UnityCodeGen.Tab(2) + "int cnt = binaryReader.ReadInt32();\n"
249 | filecontent += UnityCodeGen.Tab(2) + "byte[] bytes = binaryReader.ReadBytes(cnt);\n"
250 | filecontent += UnityCodeGen.Tab(2) + "DynamicPacket dynamicPacket = new DynamicPacket(bytes);\n"
251 | filecontent += UnityCodeGen.Tab(2) + "Deserialize(dynamicPacket);\n"
252 | filecontent += UnityCodeGen.Tab(2) + "binaryReader.Close();\n"
253 | filecontent += UnityCodeGen.Tab(2) + "fileStream.Close();\n"
254 | filecontent += UnityCodeGen.Tab(1) + "}\n"
255 |
256 | filecontent += "}\n"
257 |
258 | # 保存
259 | file = open(path, "wb")
260 | file.write(filecontent.encode())
261 | file.close()
262 |
--------------------------------------------------------------------------------
/Excel2Unity/WinRun.bat:
--------------------------------------------------------------------------------
1 |
2 | python3 main.py
3 | pause
4 |
--------------------------------------------------------------------------------
/Excel2Unity/main.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | from Excel2Unity import Excel2Unity
4 |
5 | def main():
6 | Excel2Unity().Process()
7 |
8 | if __name__ == '__main__':
9 | main()
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d409a0a09edd5c54daaf357eba4d20a0
3 | folderAsset: yes
4 | timeCreated: 1544975503
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scenes/TestExcel.unity:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!29 &1
4 | OcclusionCullingSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_OcclusionBakeSettings:
8 | smallestOccluder: 5
9 | smallestHole: 0.25
10 | backfaceThreshold: 100
11 | m_SceneGUID: 00000000000000000000000000000000
12 | m_OcclusionCullingData: {fileID: 0}
13 | --- !u!104 &2
14 | RenderSettings:
15 | m_ObjectHideFlags: 0
16 | serializedVersion: 8
17 | m_Fog: 0
18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
19 | m_FogMode: 3
20 | m_FogDensity: 0.01
21 | m_LinearFogStart: 0
22 | m_LinearFogEnd: 300
23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
26 | m_AmbientIntensity: 1
27 | m_AmbientMode: 0
28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
30 | m_HaloStrength: 0.5
31 | m_FlareStrength: 1
32 | m_FlareFadeSpeed: 3
33 | m_HaloTexture: {fileID: 0}
34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
35 | m_DefaultReflectionMode: 0
36 | m_DefaultReflectionResolution: 128
37 | m_ReflectionBounces: 1
38 | m_ReflectionIntensity: 1
39 | m_CustomReflection: {fileID: 0}
40 | m_Sun: {fileID: 0}
41 | m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
42 | --- !u!157 &3
43 | LightmapSettings:
44 | m_ObjectHideFlags: 0
45 | serializedVersion: 11
46 | m_GIWorkflowMode: 0
47 | m_GISettings:
48 | serializedVersion: 2
49 | m_BounceScale: 1
50 | m_IndirectOutputScale: 1
51 | m_AlbedoBoost: 1
52 | m_TemporalCoherenceThreshold: 1
53 | m_EnvironmentLightingMode: 0
54 | m_EnableBakedLightmaps: 1
55 | m_EnableRealtimeLightmaps: 1
56 | m_LightmapEditorSettings:
57 | serializedVersion: 9
58 | m_Resolution: 2
59 | m_BakeResolution: 40
60 | m_TextureWidth: 1024
61 | m_TextureHeight: 1024
62 | m_AO: 0
63 | m_AOMaxDistance: 1
64 | m_CompAOExponent: 1
65 | m_CompAOExponentDirect: 0
66 | m_Padding: 2
67 | m_LightmapParameters: {fileID: 0}
68 | m_LightmapsBakeMode: 1
69 | m_TextureCompression: 1
70 | m_FinalGather: 0
71 | m_FinalGatherFiltering: 1
72 | m_FinalGatherRayCount: 256
73 | m_ReflectionCompression: 2
74 | m_MixedBakeMode: 2
75 | m_BakeBackend: 0
76 | m_PVRSampling: 1
77 | m_PVRDirectSampleCount: 32
78 | m_PVRSampleCount: 500
79 | m_PVRBounces: 2
80 | m_PVRFiltering: 0
81 | m_PVRFilteringMode: 1
82 | m_PVRCulling: 1
83 | m_PVRFilteringGaussRadiusDirect: 1
84 | m_PVRFilteringGaussRadiusIndirect: 5
85 | m_PVRFilteringGaussRadiusAO: 2
86 | m_PVRFilteringAtrousColorSigma: 1
87 | m_PVRFilteringAtrousNormalSigma: 1
88 | m_PVRFilteringAtrousPositionSigma: 1
89 | m_LightingDataAsset: {fileID: 0}
90 | m_UseShadowmask: 1
91 | --- !u!196 &4
92 | NavMeshSettings:
93 | serializedVersion: 2
94 | m_ObjectHideFlags: 0
95 | m_BuildSettings:
96 | serializedVersion: 2
97 | agentTypeID: 0
98 | agentRadius: 0.5
99 | agentHeight: 2
100 | agentSlope: 45
101 | agentClimb: 0.4
102 | ledgeDropHeight: 0
103 | maxJumpAcrossDistance: 0
104 | minRegionArea: 2
105 | manualCellSize: 0
106 | cellSize: 0.16666667
107 | manualTileSize: 0
108 | tileSize: 256
109 | accuratePlacement: 0
110 | m_NavMeshData: {fileID: 0}
111 | --- !u!1 &704495376
112 | GameObject:
113 | m_ObjectHideFlags: 0
114 | m_PrefabParentObject: {fileID: 0}
115 | m_PrefabInternal: {fileID: 0}
116 | serializedVersion: 5
117 | m_Component:
118 | - component: {fileID: 704495381}
119 | - component: {fileID: 704495380}
120 | - component: {fileID: 704495379}
121 | - component: {fileID: 704495378}
122 | - component: {fileID: 704495377}
123 | m_Layer: 0
124 | m_Name: Main Camera
125 | m_TagString: MainCamera
126 | m_Icon: {fileID: 0}
127 | m_NavMeshLayer: 0
128 | m_StaticEditorFlags: 0
129 | m_IsActive: 1
130 | --- !u!81 &704495377
131 | AudioListener:
132 | m_ObjectHideFlags: 0
133 | m_PrefabParentObject: {fileID: 0}
134 | m_PrefabInternal: {fileID: 0}
135 | m_GameObject: {fileID: 704495376}
136 | m_Enabled: 1
137 | --- !u!124 &704495378
138 | Behaviour:
139 | m_ObjectHideFlags: 0
140 | m_PrefabParentObject: {fileID: 0}
141 | m_PrefabInternal: {fileID: 0}
142 | m_GameObject: {fileID: 704495376}
143 | m_Enabled: 1
144 | --- !u!92 &704495379
145 | Behaviour:
146 | m_ObjectHideFlags: 0
147 | m_PrefabParentObject: {fileID: 0}
148 | m_PrefabInternal: {fileID: 0}
149 | m_GameObject: {fileID: 704495376}
150 | m_Enabled: 1
151 | --- !u!20 &704495380
152 | Camera:
153 | m_ObjectHideFlags: 0
154 | m_PrefabParentObject: {fileID: 0}
155 | m_PrefabInternal: {fileID: 0}
156 | m_GameObject: {fileID: 704495376}
157 | m_Enabled: 1
158 | serializedVersion: 2
159 | m_ClearFlags: 1
160 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
161 | m_NormalizedViewPortRect:
162 | serializedVersion: 2
163 | x: 0
164 | y: 0
165 | width: 1
166 | height: 1
167 | near clip plane: 0.3
168 | far clip plane: 1000
169 | field of view: 60
170 | orthographic: 0
171 | orthographic size: 5
172 | m_Depth: -1
173 | m_CullingMask:
174 | serializedVersion: 2
175 | m_Bits: 4294967295
176 | m_RenderingPath: -1
177 | m_TargetTexture: {fileID: 0}
178 | m_TargetDisplay: 0
179 | m_TargetEye: 3
180 | m_HDR: 1
181 | m_AllowMSAA: 1
182 | m_ForceIntoRT: 0
183 | m_OcclusionCulling: 1
184 | m_StereoConvergence: 10
185 | m_StereoSeparation: 0.022
186 | m_StereoMirrorMode: 0
187 | --- !u!4 &704495381
188 | Transform:
189 | m_ObjectHideFlags: 0
190 | m_PrefabParentObject: {fileID: 0}
191 | m_PrefabInternal: {fileID: 0}
192 | m_GameObject: {fileID: 704495376}
193 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
194 | m_LocalPosition: {x: 0, y: 1, z: -10}
195 | m_LocalScale: {x: 1, y: 1, z: 1}
196 | m_Children: []
197 | m_Father: {fileID: 0}
198 | m_RootOrder: 0
199 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
200 | --- !u!1 &1342442946
201 | GameObject:
202 | m_ObjectHideFlags: 0
203 | m_PrefabParentObject: {fileID: 0}
204 | m_PrefabInternal: {fileID: 0}
205 | serializedVersion: 5
206 | m_Component:
207 | - component: {fileID: 1342442948}
208 | - component: {fileID: 1342442947}
209 | m_Layer: 0
210 | m_Name: Directional Light
211 | m_TagString: Untagged
212 | m_Icon: {fileID: 0}
213 | m_NavMeshLayer: 0
214 | m_StaticEditorFlags: 0
215 | m_IsActive: 1
216 | --- !u!108 &1342442947
217 | Light:
218 | m_ObjectHideFlags: 0
219 | m_PrefabParentObject: {fileID: 0}
220 | m_PrefabInternal: {fileID: 0}
221 | m_GameObject: {fileID: 1342442946}
222 | m_Enabled: 1
223 | serializedVersion: 8
224 | m_Type: 1
225 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
226 | m_Intensity: 1
227 | m_Range: 10
228 | m_SpotAngle: 30
229 | m_CookieSize: 10
230 | m_Shadows:
231 | m_Type: 2
232 | m_Resolution: -1
233 | m_CustomResolution: -1
234 | m_Strength: 1
235 | m_Bias: 0.05
236 | m_NormalBias: 0.4
237 | m_NearPlane: 0.2
238 | m_Cookie: {fileID: 0}
239 | m_DrawHalo: 0
240 | m_Flare: {fileID: 0}
241 | m_RenderMode: 0
242 | m_CullingMask:
243 | serializedVersion: 2
244 | m_Bits: 4294967295
245 | m_Lightmapping: 4
246 | m_AreaSize: {x: 1, y: 1}
247 | m_BounceIntensity: 1
248 | m_FalloffTable:
249 | m_Table[0]: 0
250 | m_Table[1]: 0
251 | m_Table[2]: 0
252 | m_Table[3]: 0
253 | m_Table[4]: 0
254 | m_Table[5]: 0
255 | m_Table[6]: 0
256 | m_Table[7]: 0
257 | m_Table[8]: 0
258 | m_Table[9]: 0
259 | m_Table[10]: 0
260 | m_Table[11]: 0
261 | m_Table[12]: 0
262 | m_ColorTemperature: 6570
263 | m_UseColorTemperature: 0
264 | m_ShadowRadius: 0
265 | m_ShadowAngle: 0
266 | --- !u!4 &1342442948
267 | Transform:
268 | m_ObjectHideFlags: 0
269 | m_PrefabParentObject: {fileID: 0}
270 | m_PrefabInternal: {fileID: 0}
271 | m_GameObject: {fileID: 1342442946}
272 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
273 | m_LocalPosition: {x: 0, y: 3, z: 0}
274 | m_LocalScale: {x: 1, y: 1, z: 1}
275 | m_Children: []
276 | m_Father: {fileID: 0}
277 | m_RootOrder: 1
278 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
279 | --- !u!1 &1814237968
280 | GameObject:
281 | m_ObjectHideFlags: 0
282 | m_PrefabParentObject: {fileID: 0}
283 | m_PrefabInternal: {fileID: 0}
284 | serializedVersion: 5
285 | m_Component:
286 | - component: {fileID: 1814237969}
287 | - component: {fileID: 1814237970}
288 | m_Layer: 0
289 | m_Name: TestExcel
290 | m_TagString: Untagged
291 | m_Icon: {fileID: 0}
292 | m_NavMeshLayer: 0
293 | m_StaticEditorFlags: 0
294 | m_IsActive: 1
295 | --- !u!4 &1814237969
296 | Transform:
297 | m_ObjectHideFlags: 0
298 | m_PrefabParentObject: {fileID: 0}
299 | m_PrefabInternal: {fileID: 0}
300 | m_GameObject: {fileID: 1814237968}
301 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
302 | m_LocalPosition: {x: 0, y: 0, z: 0}
303 | m_LocalScale: {x: 1, y: 1, z: 1}
304 | m_Children: []
305 | m_Father: {fileID: 0}
306 | m_RootOrder: 2
307 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
308 | --- !u!114 &1814237970
309 | MonoBehaviour:
310 | m_ObjectHideFlags: 0
311 | m_PrefabParentObject: {fileID: 0}
312 | m_PrefabInternal: {fileID: 0}
313 | m_GameObject: {fileID: 1814237968}
314 | m_Enabled: 1
315 | m_EditorHideFlags: 0
316 | m_Script: {fileID: 11500000, guid: c56d531f1c050d544a3ec1a43107e6dd, type: 3}
317 | m_Name:
318 | m_EditorClassIdentifier:
319 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scenes/TestExcel.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 936e400c8a8593f48ab90f57aaf0d2a7
3 | timeCreated: 1544975542
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: aee36c0b54d5b9049b3cd7877f472dab
3 | folderAsset: yes
4 | timeCreated: 1544975753
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 68d9b15592adef5438c11dadf852743c
3 | folderAsset: yes
4 | timeCreated: 1544975753
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/ConfigManager.cs:
--------------------------------------------------------------------------------
1 |
2 | //-----------------------------------------------
3 | // 生成代码不要修改
4 | //-----------------------------------------------
5 |
6 | using System.Collections;
7 | using System.Collections.Generic;
8 | using UnityEngine;
9 | using System.IO;
10 |
11 | public class ConfigManager
12 | {
13 | private static void Deserialize(DynamicPacket dynamicPacket)
14 | {
15 | Test1CfgMgr.Instance.Deserialize(dynamicPacket);
16 | Test2CfgMgr.Instance.Deserialize(dynamicPacket);
17 | Test3CfgMgr.Instance.Deserialize(dynamicPacket);
18 | }
19 |
20 | public static void LoadConfig(string cfgdatapath)
21 | {
22 | FileStream fileStream = new FileStream(cfgdatapath, FileMode.Open, FileAccess.Read);
23 | BinaryReader binaryReader = new BinaryReader(fileStream);
24 | int cnt = binaryReader.ReadInt32();
25 | byte[] bytes = binaryReader.ReadBytes(cnt);
26 | DynamicPacket dynamicPacket = new DynamicPacket(bytes);
27 | Deserialize(dynamicPacket);
28 | binaryReader.Close();
29 | fileStream.Close();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/ConfigManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 596b4ad56e646624eb62e0e327c5d5be
3 | timeCreated: 1544975753
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test1.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1af72225f038d7748b7993d4a067f7e2
3 | folderAsset: yes
4 | timeCreated: 1544975753
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test1/Test1.cs:
--------------------------------------------------------------------------------
1 |
2 | //-----------------------------------------------
3 | // 生成代码不要修改
4 | //-----------------------------------------------
5 |
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Text;
9 | using UnityEngine;
10 |
11 | public class Test1Cfg
12 | {
13 | public int ID; // int类型
14 | public float HP; // float类型
15 | public bool HasUse; // bool类型
16 | public string Name1; // string类型
17 | public string Name2; // string类型
18 | public List Vec1; // int数组
19 | public List Vec2; // float数组
20 | public List Vec4; // string数组
21 | public Dictionary Map1; // intint字典
22 | public Dictionary Map2; // intfloat字典
23 | public Dictionary Map4; // intstring字典
24 | public Dictionary Map5; // stringint字典
25 | public Dictionary Map6; // stringfloat字典
26 | public Dictionary Map8; // stringstring字典
27 |
28 | public void Deserialize (DynamicPacket packet)
29 | {
30 | ID = packet.PackReadInt32();
31 | HP = packet.PackReadFloat();
32 | HasUse = packet.PackReadBoolean();
33 | Name1 = packet.PackReadString();
34 | Name2 = packet.PackReadString();
35 | Vec1 = SheetGenCommonFunc.GetListInt(packet.PackReadString());
36 | Vec2 = SheetGenCommonFunc.GetListFloat(packet.PackReadString());
37 | Vec4 = SheetGenCommonFunc.GetListString(packet.PackReadString());
38 | Map1 = SheetGenCommonFunc.GetDictIntInt(packet.PackReadString());
39 | Map2 = SheetGenCommonFunc.GetDictIntFloat(packet.PackReadString());
40 | Map4 = SheetGenCommonFunc.GetDictIntString(packet.PackReadString());
41 | Map5 = SheetGenCommonFunc.GetDictStringInt(packet.PackReadString());
42 | Map6 = SheetGenCommonFunc.GetDictStringFloat(packet.PackReadString());
43 | Map8 = SheetGenCommonFunc.GetDictStringString(packet.PackReadString());
44 | }
45 | }
46 |
47 | public class Test1CfgMgr
48 | {
49 | private static Test1CfgMgr mInstance;
50 |
51 | public static Test1CfgMgr Instance
52 | {
53 | get
54 | {
55 | if (mInstance == null)
56 | {
57 | mInstance = new Test1CfgMgr();
58 | }
59 |
60 | return mInstance;
61 | }
62 | }
63 |
64 | private Dictionary mDict = new Dictionary();
65 |
66 | public Dictionary Dict
67 | {
68 | get {return mDict;}
69 | }
70 |
71 | public void Deserialize (DynamicPacket packet)
72 | {
73 | int num = (int)packet.PackReadInt32();
74 | for (int i = 0; i < num; i++)
75 | {
76 | Test1Cfg item = new Test1Cfg();
77 | item.Deserialize(packet);
78 | if (mDict.ContainsKey(item.ID))
79 | {
80 | mDict[item.ID] = item;
81 | }
82 | else
83 | {
84 | mDict.Add(item.ID, item);
85 | }
86 | }
87 | }
88 |
89 | public Test1Cfg GetDataByID(int id)
90 | {
91 | if(mDict.ContainsKey(id))
92 | {
93 | return mDict[id];
94 | }
95 |
96 | return null;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test1/Test1.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2ea8c138261726c479e76a3d381fe182
3 | timeCreated: 1544975753
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test2.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 20ba6a8b714acf242876d61cae4ca0ca
3 | folderAsset: yes
4 | timeCreated: 1544975753
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test2/Test2.cs:
--------------------------------------------------------------------------------
1 |
2 | //-----------------------------------------------
3 | // 生成代码不要修改
4 | //-----------------------------------------------
5 |
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Text;
9 | using UnityEngine;
10 |
11 | public class Test2Cfg
12 | {
13 | public int ID; // int类型
14 | public float HP; // float类型
15 | public bool HasUse; // bool类型
16 | public string Name1; // string类型
17 | public string Name2; // string类型
18 | public List Vec1; // int数组
19 | public List Vec2; // float数组
20 | public List Vec4; // string数组
21 | public Dictionary Map1; // intint字典
22 | public Dictionary Map2; // intfloat字典
23 | public Dictionary Map4; // intstring字典
24 | public Dictionary Map5; // stringint字典
25 | public Dictionary Map6; // stringfloat字典
26 | public Dictionary Map8; // stringstring字典
27 |
28 | public void Deserialize (DynamicPacket packet)
29 | {
30 | ID = packet.PackReadInt32();
31 | HP = packet.PackReadFloat();
32 | HasUse = packet.PackReadBoolean();
33 | Name1 = packet.PackReadString();
34 | Name2 = packet.PackReadString();
35 | Vec1 = SheetGenCommonFunc.GetListInt(packet.PackReadString());
36 | Vec2 = SheetGenCommonFunc.GetListFloat(packet.PackReadString());
37 | Vec4 = SheetGenCommonFunc.GetListString(packet.PackReadString());
38 | Map1 = SheetGenCommonFunc.GetDictIntInt(packet.PackReadString());
39 | Map2 = SheetGenCommonFunc.GetDictIntFloat(packet.PackReadString());
40 | Map4 = SheetGenCommonFunc.GetDictIntString(packet.PackReadString());
41 | Map5 = SheetGenCommonFunc.GetDictStringInt(packet.PackReadString());
42 | Map6 = SheetGenCommonFunc.GetDictStringFloat(packet.PackReadString());
43 | Map8 = SheetGenCommonFunc.GetDictStringString(packet.PackReadString());
44 | }
45 | }
46 |
47 | public class Test2CfgMgr
48 | {
49 | private static Test2CfgMgr mInstance;
50 |
51 | public static Test2CfgMgr Instance
52 | {
53 | get
54 | {
55 | if (mInstance == null)
56 | {
57 | mInstance = new Test2CfgMgr();
58 | }
59 |
60 | return mInstance;
61 | }
62 | }
63 |
64 | private List mList = new List();
65 |
66 | public List List
67 | {
68 | get {return mList;}
69 | }
70 |
71 | public void Deserialize (DynamicPacket packet)
72 | {
73 | int num = (int)packet.PackReadInt32();
74 | for (int i = 0; i < num; i++)
75 | {
76 | Test2Cfg item = new Test2Cfg();
77 | item.Deserialize(packet);
78 | mList.Add(item);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test2/Test2.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d258165df7cda6a438facd4f69f10b21
3 | timeCreated: 1544975753
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test3.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0ee9fcf4d8d6ed24bba04571c659bd9b
3 | folderAsset: yes
4 | timeCreated: 1544975753
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test3/Test3.cs:
--------------------------------------------------------------------------------
1 |
2 | //-----------------------------------------------
3 | // 生成代码不要修改
4 | //-----------------------------------------------
5 |
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Text;
9 | using UnityEngine;
10 |
11 | public class Test3Cfg
12 | {
13 | public int ID; // int类型
14 | public float HP; // float类型
15 | public bool HasUse; // bool类型
16 | public string Name1; // string类型
17 | public string Name2; // string类型
18 | public List Vec1; // int数组
19 | public List Vec2; // float数组
20 | public List Vec4; // string数组
21 | public Dictionary Map1; // intint字典
22 | public Dictionary Map2; // intfloat字典
23 | public Dictionary Map4; // intstring字典
24 | public Dictionary Map5; // stringint字典
25 | public Dictionary Map6; // stringfloat字典
26 | public Dictionary Map8; // stringstring字典
27 |
28 | public void Deserialize (DynamicPacket packet)
29 | {
30 | ID = packet.PackReadInt32();
31 | HP = packet.PackReadFloat();
32 | HasUse = packet.PackReadBoolean();
33 | Name1 = packet.PackReadString();
34 | Name2 = packet.PackReadString();
35 | Vec1 = SheetGenCommonFunc.GetListInt(packet.PackReadString());
36 | Vec2 = SheetGenCommonFunc.GetListFloat(packet.PackReadString());
37 | Vec4 = SheetGenCommonFunc.GetListString(packet.PackReadString());
38 | Map1 = SheetGenCommonFunc.GetDictIntInt(packet.PackReadString());
39 | Map2 = SheetGenCommonFunc.GetDictIntFloat(packet.PackReadString());
40 | Map4 = SheetGenCommonFunc.GetDictIntString(packet.PackReadString());
41 | Map5 = SheetGenCommonFunc.GetDictStringInt(packet.PackReadString());
42 | Map6 = SheetGenCommonFunc.GetDictStringFloat(packet.PackReadString());
43 | Map8 = SheetGenCommonFunc.GetDictStringString(packet.PackReadString());
44 | }
45 | }
46 |
47 | public class Test3CfgMgr
48 | {
49 | private static Test3CfgMgr mInstance;
50 |
51 | public static Test3CfgMgr Instance
52 | {
53 | get
54 | {
55 | if (mInstance == null)
56 | {
57 | mInstance = new Test3CfgMgr();
58 | }
59 |
60 | return mInstance;
61 | }
62 | }
63 |
64 | private List mList = new List();
65 |
66 | public List List
67 | {
68 | get {return mList;}
69 | }
70 |
71 | public void Deserialize (DynamicPacket packet)
72 | {
73 | int num = (int)packet.PackReadInt32();
74 | for (int i = 0; i < num; i++)
75 | {
76 | Test3Cfg item = new Test3Cfg();
77 | item.Deserialize(packet);
78 | mList.Add(item);
79 | }
80 | }
81 |
82 | public Test3Cfg GetDataByIDAndName1(int id, string name1)
83 | {
84 | foreach (Test3Cfg data in mList)
85 | {
86 | if (data.ID == id && data.Name1 == name1)
87 | {
88 | return data;
89 | }
90 | }
91 |
92 | return null;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Config/Test3/Test3.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 09839784c2d1c124791c425c21fdd38e
3 | timeCreated: 1544975753
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Core.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c222719766404194a850330297b4f1bb
3 | folderAsset: yes
4 | timeCreated: 1544976487
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Core/Config.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d78b8aee79f4ed14382646b0d021e1e0
3 | folderAsset: yes
4 | timeCreated: 1544976500
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Core/Config/SheetGenCommonFunc.cs:
--------------------------------------------------------------------------------
1 |
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | ///
7 | /// 表格生成公共函数
8 | ///
9 | public class SheetGenCommonFunc
10 | {
11 | public static List GetListInt(string str, char split = ';')
12 | {
13 | List templist = new List();
14 | if (str == "NULL")
15 | {
16 | return templist;
17 | }
18 | string[] strs = str.Split(split);
19 | foreach (var i in strs)
20 | {
21 | templist.Add(int.Parse(i));
22 | }
23 |
24 | return templist;
25 | }
26 |
27 | public static List GetListFloat(string str, char split = ';')
28 | {
29 | List templist = new List();
30 | string[] strs = str.Split(split);
31 | foreach (var i in strs)
32 | {
33 | templist.Add(float.Parse(i));
34 | }
35 |
36 | return templist;
37 | }
38 |
39 | public static List GetListString(string str, char split = ';')
40 | {
41 | List templist = new List();
42 | string[] strs = str.Split(split);
43 | foreach (var i in strs)
44 | {
45 | templist.Add(i);
46 | }
47 |
48 | return templist;
49 | }
50 |
51 | public static Dictionary GetDictIntInt(string str, char split1 = '|', char split2 = ';')
52 | {
53 | Dictionary tempdict = new Dictionary();
54 | string[] strs = str.Split(split1);
55 | foreach (var i in strs)
56 | {
57 | string[] strs1 = i.Split(split2);
58 | int id = 0;
59 | if (!string.IsNullOrEmpty(strs1[0]))
60 | {
61 | id = int.Parse(strs1[0]);
62 | }
63 | int value = 0;
64 | if (strs1.Length > 1)
65 | {
66 | value = int.Parse(strs1[1]);
67 | }
68 | tempdict.Add(id, value);
69 | }
70 |
71 | return tempdict;
72 | }
73 |
74 | public static Dictionary GetDictIntFloat(string str, char split1 = '|', char split2 = ';')
75 | {
76 | Dictionary tempdict = new Dictionary();
77 | string[] strs = str.Split(split1);
78 | foreach (var i in strs)
79 | {
80 | string[] strs1 = i.Split(split2);
81 | int id = 0;
82 | if (!string.IsNullOrEmpty(strs1[0]))
83 | {
84 | id = int.Parse(strs1[0]);
85 | }
86 | float value = 0f;
87 | if (strs1.Length > 1)
88 | {
89 | value = float.Parse(strs1[1]);
90 | }
91 | tempdict.Add(id, value);
92 | }
93 |
94 | return tempdict;
95 | }
96 |
97 | public static Dictionary GetDictIntString(string str, char split1 = '|', char split2 = ';')
98 | {
99 | Dictionary tempdict = new Dictionary();
100 | string[] strs = str.Split(split1);
101 | foreach (var i in strs)
102 | {
103 | string[] strs1 = i.Split(split2);
104 | int id = 0;
105 | if (!string.IsNullOrEmpty(strs1[0]))
106 | {
107 | id = int.Parse(strs1[0]);
108 | }
109 | string value = string.Empty;
110 | if (strs1.Length > 1)
111 | {
112 | value = strs1[1];
113 | }
114 | tempdict.Add(id, value);
115 | }
116 |
117 | return tempdict;
118 | }
119 |
120 | public static Dictionary GetDictStringInt(string str, char split1 = '|', char split2 = ';')
121 | {
122 | Dictionary tempdict = new Dictionary();
123 | string[] strs = str.Split(split1);
124 | foreach (var i in strs)
125 | {
126 | string[] strs1 = i.Split(split2);
127 | string id = strs1[0];
128 | int value = 0;
129 | if (strs1.Length > 1)
130 | {
131 | value = int.Parse(strs1[1]);
132 | }
133 | tempdict.Add(id, value);
134 | }
135 |
136 | return tempdict;
137 | }
138 |
139 | public static Dictionary GetDictStringFloat(string str, char split1 = '|', char split2 = ';')
140 | {
141 | Dictionary tempdict = new Dictionary();
142 | string[] strs = str.Split(split1);
143 | foreach (var i in strs)
144 | {
145 | string[] strs1 = i.Split(split2);
146 | string id = strs1[0];
147 | float value = 0f;
148 | if (strs1.Length > 1)
149 | {
150 | value = float.Parse(strs1[1]);
151 | }
152 | tempdict.Add(id, value);
153 | }
154 |
155 | return tempdict;
156 | }
157 |
158 | public static Dictionary GetDictStringString(string str, char split1 = '|', char split2 = ';')
159 | {
160 | Dictionary tempdict = new Dictionary();
161 | string[] strs = str.Split(split1);
162 | foreach (var i in strs)
163 | {
164 | string[] strs1 = i.Split(split2);
165 | string id = strs1[0];
166 | string value = string.Empty;
167 | if (strs1.Length > 1)
168 | {
169 | value = strs1[1];
170 | }
171 | tempdict.Add(id, value);
172 | }
173 |
174 | return tempdict;
175 | }
176 |
177 | public static Vector2 GetVector2(string str, char split = ';')
178 | {
179 | string[] strs = str.Split(split);
180 | return new Vector2(float.Parse(strs[0]), float.Parse(strs[1]));
181 | }
182 |
183 | public static Vector3 GetVector3(string str, char split = ';')
184 | {
185 | string[] strs = str.Split(split);
186 | return new Vector3(float.Parse(strs[0]), float.Parse(strs[1]), float.Parse(strs[2]));
187 | }
188 |
189 | public static Vector4 GetVector4(string str, char split = ';')
190 | {
191 | string[] strs = str.Split(split);
192 | return new Vector4(float.Parse(strs[0]), float.Parse(strs[1]), float.Parse(strs[2]), float.Parse(strs[3]));
193 | }
194 |
195 | public static List GetListVector2(string str, char split1 = '|', char split2 = ';')
196 | {
197 | List templist = new List();
198 | string[] strs = str.Split(split1);
199 | foreach (var i in strs)
200 | {
201 | if (i.Length <= 0)
202 | continue;
203 |
204 | templist.Add(GetVector2(i, split2));
205 | }
206 |
207 | return templist;
208 | }
209 |
210 | public static List GetListVector3(string str, char split1 = '|', char split2 = ';')
211 | {
212 | List templist = new List();
213 | string[] strs = str.Split(split1);
214 | foreach (var i in strs)
215 | {
216 | templist.Add(GetVector3(i, split2));
217 | }
218 |
219 | return templist;
220 | }
221 |
222 | public static List GetListVector4(string str, char split1 = '|', char split2 = ';')
223 | {
224 | List templist = new List();
225 | string[] strs = str.Split(split1);
226 | foreach (var i in strs)
227 | {
228 | templist.Add(GetVector4(i, split2));
229 | }
230 |
231 | return templist;
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Core/Config/SheetGenCommonFunc.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dec65a5a20637dc4abb419344ca9817c
3 | timeCreated: 1544976554
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/ExcelTest/Assets/Scripts/Core/DynamicPacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 | using UnityEngine;
6 |
7 | public class DynamicPacket
8 | {
9 | //
10 | // Fields
11 | //
12 | public BinaryWriter mWriter;
13 |
14 | public BinaryReader mReader;
15 |
16 | public MemoryStream mMemStream;
17 |
18 | //
19 | // Constructors
20 | //
21 | public DynamicPacket(byte[] bytes)
22 | : this()
23 | {
24 | this.mMemStream.Write(bytes, 0, bytes.Length);
25 | this.mMemStream.Seek(0L, SeekOrigin.Begin);
26 | }
27 |
28 | public DynamicPacket(byte[] bytes, int offset, int count)
29 | : this()
30 | {
31 | this.mMemStream.Write(bytes, offset, count);
32 | this.mMemStream.Seek(0L, SeekOrigin.Begin);
33 | }
34 |
35 | public DynamicPacket()
36 | {
37 | this.mMemStream = new MemoryStream();
38 | this.mReader = new BinaryReader(this.mMemStream);
39 | this.mWriter = new BinaryWriter(this.mMemStream);
40 | }
41 |
42 | public DynamicPacket(FileStream fs)
43 | {
44 | mReader = new BinaryReader(fs);
45 | mWriter = new BinaryWriter(fs);
46 | }
47 |
48 | public DynamicPacket(BinaryReader _reader)
49 | {
50 | mReader = _reader;
51 | }
52 |
53 | //
54 | // Methods
55 | //
56 | public virtual byte[] PackGetBuffer()
57 | {
58 | return this.mMemStream.GetBuffer();
59 | }
60 |
61 | public virtual int PackGetLength()
62 | {
63 | return (int)this.mMemStream.Length;
64 | }
65 |
66 | public void PackRead(List list)
67 | {
68 | list.Clear();
69 | UInt32 num = this.mReader.ReadUInt32();
70 | for (int i = 0; i < (int)num; i++)
71 | {
72 | list.Add(this.mReader.ReadByte());
73 | }
74 | }
75 |
76 | public void PackRead(out List list) where T : IDynamicData, new()
77 | {
78 | list = this.PackReadList();
79 | }
80 |
81 | public void PackRead(out ushort[] ushorts)
82 | {
83 | ushorts = this.PackReadUShorts();
84 | }
85 |
86 | public void PackRead(out ushort[] ushorts, int count)
87 | {
88 | ushorts = this.PackReadUShorts(count);
89 | }
90 |
91 | public void PackRead(out int[] ints)
92 | {
93 | ints = this.PackReadInts();
94 | }
95 |
96 | public void PackRead(out int[] ints, int count)
97 | {
98 | ints = this.PackReadInts(count);
99 | }
100 |
101 | public void PackRead(List list) where T : IDynamicData, new()
102 | {
103 | list.Clear();
104 | UInt32 num = this.mReader.ReadUInt32();
105 | for (int i = 0; i < (int)num; i++)
106 | {
107 | T item = (default(T) == null) ? Activator.CreateInstance() : default(T);
108 | item.Deserialize(this);
109 | list.Add(item);
110 | }
111 | }
112 |
113 | public void PackRead(out T[] array, int count) where T : IDynamicData, new()
114 | {
115 | array = this.PackReadArray(count);
116 | }
117 |
118 | public void PackRead(out short[] shorts)
119 | {
120 | shorts = this.PackReadShorts();
121 | }
122 |
123 | public void PackRead(out short[] shorts, int count)
124 | {
125 | shorts = this.PackReadShorts(count);
126 | }
127 |
128 | public void PackRead(List list)
129 | {
130 | list.Clear();
131 | UInt32 num = this.mReader.ReadUInt32();
132 | for (int i = 0; i < (int)num; i++)
133 | {
134 | list.Add(this.mReader.ReadUInt64());
135 | }
136 | }
137 |
138 | public void PackRead(HashSet set)
139 | {
140 | set.Clear();
141 | UInt32 num = this.mReader.ReadUInt32();
142 | for (int i = 0; i < (int)num; i++)
143 | {
144 | set.Add(this.mReader.ReadUInt64());
145 | }
146 | }
147 |
148 | public void PackRead(out List list)
149 | {
150 | list = this.PackReadListUInt32();
151 | }
152 |
153 | public void PackRead(List list)
154 | {
155 | list.Clear();
156 | UInt32 num = this.mReader.ReadUInt32();
157 | for (int i = 0; i < (int)num; i++)
158 | {
159 | list.Add(this.mReader.ReadInt32());
160 | }
161 | }
162 |
163 | public void PackRead(out List list)
164 | {
165 | list = this.PackReadListByte();
166 | }
167 |
168 | public void PackRead(List list)
169 | {
170 | list.Clear();
171 | UInt32 num = this.mReader.ReadUInt32();
172 | for (int i = 0; i < (int)num; i++)
173 | {
174 | list.Add(this.mReader.ReadUInt32());
175 | }
176 | }
177 |
178 | public void PackRead(out List list)
179 | {
180 | list = this.PackReadListInt32();
181 | }
182 |
183 | public void PackRead(out T[] array) where T : IDynamicData, new()
184 | {
185 | array = this.PackReadArray();
186 | }
187 |
188 | public void PackRead(out ulong[] ulongs, int count)
189 | {
190 | ulongs = this.PackReadULongs(count);
191 | }
192 |
193 | public void PackRead(out long i)
194 | {
195 | i = this.mReader.ReadInt64();
196 | }
197 |
198 | public void PackRead(out ulong i)
199 | {
200 | i = this.mReader.ReadUInt64();
201 | }
202 |
203 | public void PackRead(out ulong[] ulongs)
204 | {
205 | ulongs = this.PackReadULongs();
206 | }
207 |
208 | public void PackRead(out short i)
209 | {
210 | i = this.mReader.ReadInt16();
211 | }
212 |
213 | public void PackRead(out ushort i)
214 | {
215 | i = this.mReader.ReadUInt16();
216 | }
217 |
218 | public void PackRead(out uint i)
219 | {
220 | i = this.mReader.ReadUInt32();
221 | }
222 |
223 | public void PackRead(out int i)
224 | {
225 | i = this.mReader.ReadInt32();
226 | }
227 |
228 | public void PackRead(out uint[] uints, int count)
229 | {
230 | uints = this.PackReadUInts(count);
231 | }
232 |
233 | public void PackRead(out decimal d)
234 | {
235 | d = this.mReader.ReadDecimal();
236 | }
237 |
238 | public void PackRead(T data) where T : IDynamicData
239 | {
240 | data.Deserialize(this);
241 | }
242 |
243 | public void PackRead(out uint[] uints)
244 | {
245 | uints = this.PackReadUInts();
246 | }
247 |
248 | public void PackRead(out long[] longs, int count)
249 | {
250 | longs = this.PackReadLongs(count);
251 | }
252 |
253 | public void PackRead(out float f)
254 | {
255 | f = this.mReader.ReadSingle();
256 | }
257 |
258 | public void PackRead(out double d)
259 | {
260 | d = this.mReader.ReadDouble();
261 | }
262 |
263 | public void PackRead(out long[] longs)
264 | {
265 | longs = this.PackReadLongs();
266 | }
267 |
268 | public void PackRead(out List list)
269 | {
270 | list = this.PackReadListUInt64();
271 | }
272 |
273 | public void PackRead(out bool b)
274 | {
275 | b = this.mReader.ReadBoolean();
276 | }
277 |
278 | public void PackRead(Dictionary diction) where T : IDynamicData, new()
279 | {
280 | diction.Clear();
281 | UInt32 num = this.PackReadUInt32();
282 | for (int i = 0; i < (int)num; i++)
283 | {
284 | byte key = this.mReader.ReadByte();
285 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
286 | value.Deserialize(this);
287 | diction.Add(key, value);
288 | }
289 | }
290 |
291 | public void PackRead(Dictionary diction) where T : IDynamicData, new()
292 | {
293 | diction.Clear();
294 | UInt32 num = this.PackReadUInt32();
295 | for (int i = 0; i < (int)num; i++)
296 | {
297 | sbyte key = this.mReader.ReadSByte();
298 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
299 | value.Deserialize(this);
300 | diction.Add(key, value);
301 | }
302 | }
303 |
304 | public void PackRead(Dictionary diction) where T : IDynamicData, new()
305 | {
306 | diction.Clear();
307 | UInt32 num = this.PackReadUInt32();
308 | for (int i = 0; i < (int)num; i++)
309 | {
310 | int key = this.mReader.ReadInt32();
311 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
312 | value.Deserialize(this);
313 | diction.Add(key, value);
314 | }
315 | }
316 |
317 | public void PackRead(Dictionary diction) where T : IDynamicData, new()
318 | {
319 | diction.Clear();
320 | UInt32 num = this.PackReadUInt32();
321 | for (int i = 0; i < (int)num; i++)
322 | {
323 | uint key = this.mReader.ReadUInt32();
324 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
325 | value.Deserialize(this);
326 | diction.Add(key, value);
327 | }
328 | }
329 |
330 | public void PackRead(Dictionary diction) where T : IDynamicData, new()
331 | {
332 | diction.Clear();
333 | UInt32 num = this.PackReadUInt32();
334 | for (int i = 0; i < (int)num; i++)
335 | {
336 | string key = this.mReader.ReadString();
337 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
338 | value.Deserialize(this);
339 | diction.Add(key, value);
340 | }
341 | }
342 |
343 | public void PackRead(Dictionary diction) where T : IDynamicData, new()
344 | {
345 | diction.Clear();
346 | UInt32 num = this.PackReadUInt32();
347 | for (int i = 0; i < (int)num; i++)
348 | {
349 | ulong key = this.mReader.ReadUInt64();
350 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
351 | value.Deserialize(this);
352 | diction.Add(key, value);
353 | }
354 | }
355 |
356 | public void PackRead(SortedDictionary diction) where T : IDynamicData, new()
357 | {
358 | diction.Clear();
359 | UInt32 num = this.PackReadUInt32();
360 | for (int i = 0; i < (int)num; i++)
361 | {
362 | byte key = this.mReader.ReadByte();
363 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
364 | value.Deserialize(this);
365 | diction.Add(key, value);
366 | }
367 | }
368 |
369 | public void PackRead(SortedDictionary diction) where T : IDynamicData, new()
370 | {
371 | diction.Clear();
372 | UInt32 num = this.PackReadUInt32();
373 | for (int i = 0; i < (int)num; i++)
374 | {
375 | sbyte key = this.mReader.ReadSByte();
376 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
377 | value.Deserialize(this);
378 | diction.Add(key, value);
379 | }
380 | }
381 |
382 | public void PackRead(SortedDictionary diction) where T : IDynamicData, new()
383 | {
384 | diction.Clear();
385 | UInt32 num = this.PackReadUInt32();
386 | for (int i = 0; i < (int)num; i++)
387 | {
388 | int key = this.mReader.ReadInt32();
389 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
390 | value.Deserialize(this);
391 | diction.Add(key, value);
392 | }
393 | }
394 |
395 | public void PackRead(SortedDictionary diction) where T : IDynamicData, new()
396 | {
397 | diction.Clear();
398 | UInt32 num = this.PackReadUInt32();
399 | for (int i = 0; i < (int)num; i++)
400 | {
401 | uint key = this.mReader.ReadUInt32();
402 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
403 | value.Deserialize(this);
404 | diction.Add(key, value);
405 | }
406 | }
407 |
408 | public void PackRead(SortedDictionary diction) where T : IDynamicData, new()
409 | {
410 | diction.Clear();
411 | UInt32 num = this.PackReadUInt32();
412 | for (int i = 0; i < (int)num; i++)
413 | {
414 | string key = this.mReader.ReadString();
415 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
416 | value.Deserialize(this);
417 | diction.Add(key, value);
418 | }
419 | }
420 |
421 | public void PackRead(SortedDictionary diction) where T : IDynamicData, new()
422 | {
423 | diction.Clear();
424 | UInt32 num = this.PackReadUInt32();
425 | for (int i = 0; i < (int)num; i++)
426 | {
427 | ulong key = this.mReader.ReadUInt64();
428 | T value = (default(T) == null) ? Activator.CreateInstance() : default(T);
429 | value.Deserialize(this);
430 | diction.Add(key, value);
431 | }
432 | }
433 |
434 | public void PackRead(out string str)
435 | {
436 | str = this.PackReadString();
437 | }
438 |
439 | public void PackRead(Dictionary diction)
440 | where TK : IDynamicData, new()
441 | where TV : IDynamicData, new()
442 | {
443 | diction.Clear();
444 | UInt32 num = this.PackReadUInt32();
445 | for (int i = 0; i < (int)num; i++)
446 | {
447 | TK key = (default(TK) == null) ? Activator.CreateInstance() : default(TK);
448 | key.Deserialize(this);
449 | TV value = (default(TV) == null) ? Activator.CreateInstance() : default(TV);
450 | value.Deserialize(this);
451 | diction.Add(key, value);
452 | }
453 | }
454 |
455 | public void PackRead(SortedDictionary diction)
456 | where TK : IDynamicData, new()
457 | where TV : IDynamicData, new()
458 | {
459 | diction.Clear();
460 | UInt32 num = this.PackReadUInt32();
461 | for (int i = 0; i < (int)num; i++)
462 | {
463 | TK key = (default(TK) == null) ? Activator.CreateInstance() : default(TK);
464 | key.Deserialize(this);
465 | TV value = (default(TV) == null) ? Activator.CreateInstance() : default(TV);
466 | value.Deserialize(this);
467 | diction.Add(key, value);
468 | }
469 | }
470 |
471 | public void PackRead(out byte b)
472 | {
473 | b = this.mReader.ReadByte();
474 | }
475 |
476 | public void PackRead(out Dictionary diction) where T : IDynamicData, new()
477 | {
478 | diction = this.PackReadDictionByte();
479 | }
480 |
481 | public void PackRead(out Dictionary diction) where T : IDynamicData, new()
482 | {
483 | diction = this.PackReadDictionInt32();
484 | }
485 |
486 | public void PackRead(out Dictionary diction) where T : IDynamicData, new()
487 | {
488 | diction = this.PackReadDictionUInt32();
489 | }
490 |
491 | public void PackRead(out SortedDictionary diction) where T : IDynamicData, new()
492 | {
493 | diction = this.PackReadSortedDictionByte();
494 | }
495 |
496 | public void PackRead(out SortedDictionary diction) where T : IDynamicData, new()
497 | {
498 | diction = this.PackReadSortedDictionInt32();
499 | }
500 |
501 | public void PackRead(out SortedDictionary diction) where T : IDynamicData, new()
502 | {
503 | diction = this.PackReadSortedDictionUInt32();
504 | }
505 |
506 | public void PackRead(out char c)
507 | {
508 | c = this.mReader.ReadChar();
509 | }
510 |
511 | public void PackRead(out Dictionary diction)
512 | {
513 | diction = this.PackReadDictionStringString();
514 | }
515 |
516 | public void PackRead(Dictionary diction)
517 | {
518 | UInt32 num = this.PackReadUInt32();
519 | for (int i = 0; i < (int)num; i++)
520 | {
521 | string key = this.PackReadString();
522 | string value = this.PackReadString();
523 | diction.Add(key, value);
524 | }
525 | }
526 |
527 | public void PackRead(out Dictionary diction)
528 | {
529 | diction = this.PackReadDictionInt32Int32();
530 | }
531 |
532 | public void PackRead(out Dictionary diction)
533 | {
534 | diction = this.PackReadDictionUInt32UInt32();
535 | }
536 |
537 | public void PackRead(out Dictionary diction)
538 | {
539 | diction = this.PackReadDictionUInt32UInt16();
540 | }
541 |
542 | public void PackRead(out SortedDictionary diction)
543 | {
544 | diction = this.PackReadSortedDictionStringString();
545 | }
546 |
547 | public void PackRead(SortedDictionary diction)
548 | {
549 | UInt32 num = this.PackReadUInt32();
550 | for (int i = 0; i < (int)num; i++)
551 | {
552 | string key = this.PackReadString();
553 | string value = this.PackReadString();
554 | diction.Add(key, value);
555 | }
556 | }
557 |
558 | public void PackRead(out SortedDictionary diction)
559 | {
560 | diction = this.PackReadSortedDictionInt32Int32();
561 | }
562 |
563 | public void PackRead(out SortedDictionary diction)
564 | {
565 | diction = this.PackReadSortedDictionUInt32UInt32();
566 | }
567 |
568 | public void PackRead(out SortedDictionary diction)
569 | {
570 | diction = this.PackReadSortedDictionUInt32UInt16();
571 | }
572 |
573 | public void PackRead(out char[] chars)
574 | {
575 | ushort count = this.mReader.ReadUInt16();
576 | chars = this.mReader.ReadChars((int)count);
577 | }
578 |
579 | public void PackRead(Dictionary diction)
580 | {
581 | diction.Clear();
582 | UInt32 num = this.PackReadUInt32();
583 | for (int i = 0; i < (int)num; i++)
584 | {
585 | int key = this.mReader.ReadInt32();
586 | int value = this.mReader.ReadInt32();
587 | diction.Add(key, value);
588 | }
589 | }
590 |
591 | public void PackRead(Dictionary diction)
592 | {
593 | diction.Clear();
594 | UInt32 num = this.PackReadUInt32();
595 | for (int i = 0; i < (int)num; i++)
596 | {
597 | uint key = this.mReader.ReadUInt32();
598 | uint value = this.mReader.ReadUInt32();
599 | diction.Add(key, value);
600 | }
601 | }
602 |
603 | public void PackRead(SortedDictionary diction)
604 | {
605 | diction.Clear();
606 | UInt32 num = this.PackReadUInt32();
607 | for (int i = 0; i < (int)num; i++)
608 | {
609 | int key = this.mReader.ReadInt32();
610 | int value = this.mReader.ReadInt32();
611 | diction.Add(key, value);
612 | }
613 | }
614 |
615 | public void PackRead(SortedDictionary diction)
616 | {
617 | diction.Clear();
618 | UInt32 num = this.PackReadUInt32();
619 | for (int i = 0; i < (int)num; i++)
620 | {
621 | uint key = this.mReader.ReadUInt32();
622 | uint value = this.mReader.ReadUInt32();
623 | diction.Add(key, value);
624 | }
625 | }
626 |
627 | public void PackRead(out sbyte b)
628 | {
629 | b = this.mReader.ReadSByte();
630 | }
631 |
632 | public void PackRead(out List list)
633 | {
634 | list = this.PackReadListString();
635 | }
636 |
637 | public void PackRead(List list)
638 | {
639 | list.Clear();
640 | UInt32 num = this.mReader.ReadUInt32();
641 | for (int i = 0; i < (int)num; i++)
642 | {
643 | list.Add(this.mReader.ReadSingle());
644 | }
645 | }
646 |
647 | public void PackRead(out byte[] bytes, int count)
648 | {
649 | bytes = this.PackReadBytes(count);
650 | }
651 |
652 | public void PackRead(List list)
653 | {
654 | list.Clear();
655 | UInt32 num = this.mReader.ReadUInt32();
656 | for (int i = 0; i < (int)num; i++)
657 | {
658 | list.Add(this.PackReadString());
659 | }
660 | }
661 |
662 | public void PackRead(out sbyte[] bytes, int count)
663 | {
664 | bytes = this.PackReadSBytes(count);
665 | }
666 |
667 | public void PackRead(out List list)
668 | {
669 | list = this.PackReadListFloat();
670 | }
671 |
672 | public void PackRead(out sbyte[] bytes)
673 | {
674 | bytes = this.PackReadSBytes();
675 | }
676 |
677 | public void PackRead(out Dictionary diction)
678 | where TK : IDynamicData, new()
679 | where TV : IDynamicData, new()
680 | {
681 | diction = this.PackReadDiction();
682 | }
683 |
684 | public void PackRead(out SortedDictionary diction)
685 | where TK : IDynamicData, new()
686 | where TV : IDynamicData, new()
687 | {
688 | diction = this.PackReadSortedDiction();
689 | }
690 |
691 | public void PackRead(out byte[] bytes)
692 | {
693 | bytes = this.PackReadBytes();
694 | }
695 |
696 | public T[] PackReadArray() where T : IDynamicData, new()
697 | {
698 | UInt32 count = this.mReader.ReadUInt32();
699 | return this.PackReadArray((int)count);
700 | }
701 |
702 | public T[] PackReadArray(int count) where T : IDynamicData, new()
703 | {
704 | T[] array = new T[count];
705 | for (int i = 0; i < count; i++)
706 | {
707 | array[i] = ((default(T) == null) ? Activator.CreateInstance() : default(T));
708 | array[i].Deserialize(this);
709 | }
710 | return array;
711 | }
712 |
713 | public bool PackReadBoolean()
714 | {
715 | return this.mReader.ReadBoolean();
716 | }
717 |
718 | public byte PackReadByte()
719 | {
720 | return this.mReader.ReadByte();
721 | }
722 |
723 | public byte[] PackReadshortBytes()
724 | {
725 | UInt32 count = (UInt32)this.mReader.ReadUInt16();
726 | return this.PackReadBytes((int)count);
727 | }
728 |
729 | public byte[] PackReadBytes()
730 | {
731 | UInt32 count = this.mReader.ReadUInt32();
732 | return this.PackReadBytes((int)count);
733 | }
734 |
735 | public byte[] PackReadBytes(int count)
736 | {
737 | byte[] array = new byte[count];
738 | for (int i = 0; i < count; i++)
739 | {
740 | array[i] = this.mReader.ReadByte();
741 | }
742 | return array;
743 | }
744 |
745 | public char PackReadChar()
746 | {
747 | return this.mReader.ReadChar();
748 | }
749 |
750 | public char[] PackReadChars(int count)
751 | {
752 | return this.mReader.ReadChars(count);
753 | }
754 |
755 | public char[] PackReadChars()
756 | {
757 | ushort count = this.mReader.ReadUInt16();
758 | return this.mReader.ReadChars((int)count);
759 | }
760 |
761 | public T PackReadData() where T : IDynamicData, new()
762 | {
763 | T result = (default(T) == null) ? Activator.CreateInstance() : default(T);
764 | result.Deserialize(this);
765 | return result;
766 | }
767 |
768 | public decimal PackReadDecimal()
769 | {
770 | return this.mReader.ReadDecimal();
771 | }
772 |
773 | public Dictionary PackReadDiction()
774 | where TK : IDynamicData, new()
775 | where TV : IDynamicData, new()
776 | {
777 | Dictionary dictionary = new Dictionary();
778 | this.PackRead(dictionary);
779 | return dictionary;
780 | }
781 |
782 | public Dictionary PackReadDictionByte() where T : IDynamicData, new()
783 | {
784 | Dictionary dictionary = new Dictionary();
785 | this.PackRead(dictionary);
786 | return dictionary;
787 | }
788 | public Dictionary PackReadDictionSByte() where T : IDynamicData, new()
789 | {
790 | Dictionary dictionary = new Dictionary();
791 | this.PackRead(dictionary);
792 | return dictionary;
793 | }
794 |
795 | public Dictionary PackReadDictionUInt32() where T : IDynamicData, new()
796 | {
797 | Dictionary dictionary = new Dictionary();
798 | this.PackRead(dictionary);
799 | return dictionary;
800 | }
801 | public Dictionary PackReadDictionInt32() where T : IDynamicData, new()
802 | {
803 | Dictionary dictionary = new Dictionary();
804 | this.PackRead(dictionary);
805 | return dictionary;
806 | }
807 | public Dictionary PackReadDictionUInt64() where T : IDynamicData, new()
808 | {
809 | Dictionary dictionary = new Dictionary();
810 | this.PackRead(dictionary);
811 | return dictionary;
812 | }
813 |
814 | public Dictionary PackReadDictionUInt32SByte()
815 | {
816 | Dictionary dictionary = new Dictionary();
817 | UInt32 num = this.PackReadUInt32();
818 | for (int i = 0; i < (int)num; i++)
819 | {
820 | uint key = this.mReader.ReadUInt32();
821 | sbyte value = this.mReader.ReadSByte();
822 | if (!dictionary.ContainsKey(key))
823 | dictionary.Add(key, value);
824 | else
825 | dictionary[key] = value;
826 | }
827 | return dictionary;
828 | }
829 |
830 | public Dictionary PackReadDictionUInt32Byte()
831 | {
832 | Dictionary dictionary = new Dictionary();
833 | UInt32 num = this.PackReadUInt32();
834 | for (int i = 0; i < (int)num; i++)
835 | {
836 | uint key = this.mReader.ReadUInt32();
837 | byte value = this.mReader.ReadByte();
838 | if (!dictionary.ContainsKey(key))
839 | dictionary.Add(key, value);
840 | else
841 | dictionary[key] = value;
842 | }
843 | return dictionary;
844 | }
845 |
846 | public Dictionary PackReadDictionUInt64Byte()
847 | {
848 | Dictionary dictionary = new Dictionary();
849 | UInt32 num = this.PackReadUInt32();
850 | for (int i = 0; i < (int)num; i++)
851 | {
852 | ulong key = this.mReader.ReadUInt64();
853 | byte value = this.mReader.ReadByte();
854 | if (!dictionary.ContainsKey(key))
855 | dictionary.Add(key, value);
856 | else
857 | dictionary[key] = value;
858 | }
859 | return dictionary;
860 | }
861 |
862 | public Dictionary PackReadDictionUInt32UInt64()
863 | {
864 | Dictionary dictionary = new Dictionary();
865 | UInt32 num = this.PackReadUInt32();
866 | for (int i = 0; i < (int)num; i++)
867 | {
868 | uint key = this.mReader.ReadUInt32();
869 | ulong value = this.mReader.ReadUInt64();
870 | if (!dictionary.ContainsKey(key))
871 | dictionary.Add(key, value);
872 | else
873 | dictionary[key] = value;
874 | }
875 | return dictionary;
876 | }
877 |
878 | public Dictionary PackReadDictionUInt64Int32()
879 | {
880 | Dictionary dictionary = new Dictionary();
881 | UInt32 num = this.PackReadUInt32();
882 | for (int i = 0; i < (int)num; i++)
883 | {
884 | ulong key = this.mReader.ReadUInt64();
885 | int value = this.mReader.ReadInt32();
886 | if (!dictionary.ContainsKey(key))
887 | dictionary.Add(key, value);
888 | else
889 | dictionary[key] = value;
890 | }
891 | return dictionary;
892 | }
893 |
894 | public Dictionary PackReadDictionUInt32UInt16()
895 | {
896 | Dictionary dictionary = new Dictionary();
897 | UInt32 num = this.PackReadUInt32();
898 | for (int i = 0; i < (int)num; i++)
899 | {
900 | uint key = this.mReader.ReadUInt32();
901 | UInt16 value = this.mReader.ReadUInt16();
902 | if (!dictionary.ContainsKey(key))
903 | dictionary.Add(key, value);
904 | else
905 | dictionary[key] = value;
906 | }
907 | return dictionary;
908 | }
909 |
910 | public Dictionary PackReadDictionUInt32UInt32()
911 | {
912 | Dictionary dictionary = new Dictionary();
913 | UInt32 num = this.PackReadUInt32();
914 | for (int i = 0; i < (int)num; i++)
915 | {
916 | uint key = this.mReader.ReadUInt32();
917 | uint value = this.mReader.ReadUInt32();
918 | if (!dictionary.ContainsKey(key))
919 | dictionary.Add(key, value);
920 | else
921 | dictionary[key] = value;
922 | }
923 | return dictionary;
924 | }
925 |
926 | public Dictionary PackReadDictionInt32UInt32()
927 | {
928 | Dictionary dictionary = new Dictionary();
929 | UInt32 num = this.PackReadUInt32();
930 | for (int i = 0; i < (int)num; i++)
931 | {
932 | int key = this.mReader.ReadInt32();
933 | uint value = this.mReader.ReadUInt32();
934 | if (!dictionary.ContainsKey(key))
935 | dictionary.Add(key, value);
936 | else
937 | dictionary[key] = value;
938 | }
939 | return dictionary;
940 | }
941 |
942 | public Dictionary PackReadDictionUInt16UInt32()
943 | {
944 | Dictionary dictionary = new Dictionary();
945 | UInt32 num = this.PackReadUInt32();
946 | for (int i = 0; i < (int)num; i++)
947 | {
948 | ushort key = this.mReader.ReadUInt16();
949 | uint value = this.mReader.ReadUInt32();
950 | if (!dictionary.ContainsKey(key))
951 | dictionary.Add(key, value);
952 | else
953 | dictionary[key] = value;
954 | }
955 | return dictionary;
956 | }
957 |
958 | public Dictionary PackReadDictionUInt16Float()
959 | {
960 | Dictionary dictionary = new Dictionary();
961 | UInt32 num = this.PackReadUInt32();
962 | for (int i = 0; i < (int)num; i++)
963 | {
964 | ushort key = this.mReader.ReadUInt16();
965 | float value = this.mReader.ReadSingle();
966 | if (!dictionary.ContainsKey(key))
967 | dictionary.Add(key, value);
968 | else
969 | dictionary[key] = value;
970 | }
971 | return dictionary;
972 | }
973 |
974 | public Dictionary PackReadDictionUInt32Int32()
975 | {
976 | Dictionary