1.AB包相关配置

GF资源管理实属牛批,但要使用它,并不是全自动的,还是要配置一下

创建一个静态类,类名随意,注意里面至少要包含以下三个属性,后面的地址所指就是打AB包所必须的三个配置文件(这个地址可以自己更改,注意改变路径就行)

1
2
3
4
5
6
7
8
 [AssetBundleBuilderConfigPath] public static string AssetBundleBuilderConfig =
Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleBuilder.xml");

[AssetBundleEditorConfigPath] public static string AssetBundleEditorConfig =
Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleEditor.xml");

[AssetBundleCollectionConfigPath] public static string AssetBundleCollectionConfig =
Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleCollection.xml");

其中除了AssetBundleEditor.xml,其余两个都可以在打包的时候自动升成。所以我们要指定目录创建AssetBundleEditor.xml文件,并在里面填入以下信息

其中SourceAssetRootPath是指定资源根目录位置的,自己注意视情况更改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 <?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
<AssetBundleEditor>
<Settings>
<SourceAssetRootPath>Assets/GameMain</SourceAssetRootPath>
<SourceAssetSearchPaths>
<SourceAssetSearchPath RelativePath=""/>
</SourceAssetSearchPaths>
<SourceAssetUnionTypeFilter>t:Scene t:Prefab t:Shader t:Model t:Material t:Texture t:AudioClip
t:AnimationClip t:AnimatorController t:Font t:TextAsset t:ScriptableObject
</SourceAssetUnionTypeFilter>
<SourceAssetUnionLabelFilter>l:AssetBundleInclusive</SourceAssetUnionLabelFilter>
<SourceAssetExceptTypeFilter>t:Script</SourceAssetExceptTypeFilter>
<SourceAssetExceptLabelFilter>l:AssetBundleExclusive</SourceAssetExceptLabelFilter>
<AssetSorter>Name</AssetSorter>
</Settings>
</AssetBundleEditor>
</UnityGameFramework>

2.UI模块相关

说实话我没想到使用UI模块会出那么多变故。。。我花了半天时间才找到问题所在。。。

首先要创建并设置一个默认Canvas,因为没有Canvas的支撑,UGUI无法正确显示

再搞一个UGuiGroupHelper

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
 //------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年1月11日 23:35:22
//------------------------------------------------------------

using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;

namespace GameMain.Scripts.UI
{
public class UGuiGroupHelper : UIGroupHelperBase
{
public const int DepthFactor = 1000;

private int m_Depth = 0;
private Canvas m_CachedCanvas = null;

/// <summary>
/// 设置界面组深度。
/// </summary>
/// <param name="depth">界面组深度。</param>
public override void SetDepth(int depth)
{
m_Depth = depth;
m_CachedCanvas.overrideSorting = true;
m_CachedCanvas.sortingOrder = DepthFactor * depth;
}

private void Awake()
{
m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
gameObject.GetOrAddComponent<GraphicRaycaster>();
}

private void Start()
{
m_CachedCanvas.overrideSorting = true;
m_CachedCanvas.sortingOrder = DepthFactor * m_Depth;

RectTransform transform = GetComponent<RectTransform>();
transform.anchorMin = Vector2.zero;
transform.anchorMax = Vector2.one;
transform.anchoredPosition = Vector2.zero;
transform.sizeDelta = Vector2.zero;
}
}
}

按下图所示替换默认的辅助器

然后是UGuiForm

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
50
51
52
53
54
55
56
57
58
59
60
61
62
 //------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年1月11日 23:42:05
//------------------------------------------------------------

using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;

namespace GameMain.Scripts.UI
{
public class UGuiForm : UIFormLogic
{
private Canvas m_CachedCanvas = null;

public const int DepthFactor = 100;
public int OriginalDepth
{
get;
private set;
}

public int Depth
{
get
{
return m_CachedCanvas.sortingOrder;
}
}

protected override void OnInit(object userData)
{
base.OnInit(userData);

m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
m_CachedCanvas.overrideSorting = true;
OriginalDepth = m_CachedCanvas.sortingOrder;

RectTransform transform = GetComponent<RectTransform>();
transform.anchorMin = Vector2.zero;
transform.anchorMax = Vector2.one;
transform.anchoredPosition = Vector2.zero;
transform.sizeDelta = Vector2.zero;

gameObject.GetOrAddComponent<GraphicRaycaster>();
}

protected override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
{
int oldDepth = Depth;
base.OnDepthChanged(uiGroupDepth, depthInUIGroup);
int deltaDepth = UGuiGroupHelper.DepthFactor * uiGroupDepth + DepthFactor * depthInUIGroup - oldDepth +
OriginalDepth;
Canvas[] canvases = GetComponentsInChildren<Canvas>(true);
for (int i = 0; i < canvases.Length; i++)
{
canvases[i].sortingOrder += deltaDepth;
}
}
}
}

每个UIForm都要继承这个类

至此,你做的UI效果,才是你想要的效果。。。

最后,配置表里面的被其他UI遮挡是否会暂停,只会在同一UI Group下面生效

3.配表相关

保存的时候选择-文本文件(制表符分隔)

在Unity中应当能识别其数据

没有的话,就用文本文档打开,另存为UTF-8

4:使用类自动生成工具

先在Scripts下面新建如下

(重要部分E大和我已经打上注释,请注意查看,PS:代码全部为E大所开发,本人只是将自己的理解传达给大家,文件头的Author请自动忽略)

他们依次为

DataTableCodeTemplate.txt

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
 //------------------------------------------------------------
// Game Framework
// Copyright © 2013-2019 Jiang Yin. All rights reserved.
// Homepage: http://gameframework.cn/
// Feedback: mailto:jiangyin@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间:__DATA_TABLE_CREATE_TIME__
//------------------------------------------------------------

using GameFramework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace __DATA_TABLE_NAME_SPACE__
{
/// <summary>
/// __DATA_TABLE_COMMENT__
/// </summary>
public class __DATA_TABLE_CLASS_NAME__ : DataRowBase
{
private int m_Id = 0;

/// <summary>
/// __DATA_TABLE_ID_COMMENT__
/// </summary>
public override int Id
{
get
{
return m_Id;
}
}

__DATA_TABLE_PROPERTIES__

__DATA_TABLE_STRING_PARSER__

__DATA_TABLE_BYTES_PARSER__

__DATA_TABLE_STREAM_PARSER__

__DATA_TABLE_PROPERTY_ARRAY__
}
}
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
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
140
141
142
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
 //------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年2月10日
//------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using GameFramework;
using UnityEngine;
using UnityGameFramework.Editor.DataTableTools;

namespace Assets.GameMain.Scripts.DataTable.DataTableGenerator
{
public class DataTableGenerator
{
//数据表(.txt文件所在位置)
private const string DataTablePath = "Assets/GameMain/DataTables";
//生成的CSharp类所在位置
private const string CSharpCodePath = "Assets/GameMain/Scripts/DataTable";
//用于临时存读CSharp代码的txt文件所在位置(如果没有,请创建)
private const string CSharpCodeTemplateFileName = "Assets/GameMain/Configs/DataTableCodeTemplate.txt";
private static readonly Regex EndWithNumberRegex = new Regex(@"\d+$");
private static readonly Regex NameRegex = new Regex(@"^[A-Z][A-Za-z0-9_]+$");

public static DataTableProcessor CreateDataTableProcessor(string dataTableName)
{
return new DataTableProcessor(Utility.Path.GetCombinePath(DataTablePath, dataTableName + ".txt"), Encoding.Default, 1, 2, null, 3, 4, 1);
}

public static bool CheckRawData(DataTableProcessor dataTableProcessor, string dataTableName)
{
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
string name = dataTableProcessor.GetName(i);
if (string.IsNullOrEmpty(name) || name == "#")
{
continue;
}

if (!NameRegex.IsMatch(name))
{
Debug.LogWarning(Utility.Text.Format("Check raw data failure. DataTableName='{0}' Name='{1}'", dataTableName, name));
return false;
}
}

return true;
}

public static void GenerateDataFile(DataTableProcessor dataTableProcessor, string dataTableName)
{
string binaryDataFileName = Utility.Path.GetCombinePath(DataTablePath, dataTableName + ".bytes");
if (!dataTableProcessor.GenerateDataFile(binaryDataFileName, Encoding.UTF8) && File.Exists(binaryDataFileName))
{
File.Delete(binaryDataFileName);
}
}

public static void GenerateCodeFile(DataTableProcessor dataTableProcessor, string dataTableName)
{
dataTableProcessor.SetCodeTemplate(CSharpCodeTemplateFileName, Encoding.UTF8);
dataTableProcessor.SetCodeGenerator(DataTableCodeGenerator);

string csharpCodeFileName = Utility.Path.GetCombinePath(CSharpCodePath, "DR" + dataTableName + ".cs");
if (!dataTableProcessor.GenerateCodeFile(csharpCodeFileName, Encoding.UTF8, dataTableName) && File.Exists(csharpCodeFileName))
{
File.Delete(csharpCodeFileName);
}
}

private static void DataTableCodeGenerator(DataTableProcessor dataTableProcessor, StringBuilder codeContent, object userData)
{
string dataTableName = (string)userData;

codeContent.Replace("__DATA_TABLE_CREATE_TIME__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
//所生成的CSharp类的命名空间,请保证它与BinaryReaderExtension.cs和DataTableExtension.cs的命名空间一致,否则将不能正确解析
codeContent.Replace("__DATA_TABLE_NAME_SPACE__", "Assets.GameMain.Scripts.DataTable");
codeContent.Replace("__DATA_TABLE_CLASS_NAME__", "DR" + dataTableName);
codeContent.Replace("__DATA_TABLE_COMMENT__", dataTableProcessor.GetValue(0, 1) + "。");
codeContent.Replace("__DATA_TABLE_ID_COMMENT__", "获取" + dataTableProcessor.GetComment(dataTableProcessor.IdColumn) + "。");
codeContent.Replace("__DATA_TABLE_PROPERTIES__", GenerateDataTableProperties(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_STRING_PARSER__", GenerateDataTableStringParser(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_BYTES_PARSER__", GenerateDataTableBytesParser(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_STREAM_PARSER__", GenerateDataTableStreamParser(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_PROPERTY_ARRAY__", GenerateDataTablePropertyArray(dataTableProcessor));
}

private static string GenerateDataTableProperties(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
bool firstProperty = true;
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
continue;
}

if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
continue;
}

if (firstProperty)
{
firstProperty = false;
}
else
{
stringBuilder.AppendLine().AppendLine();
}

stringBuilder
.AppendLine(" /// <summary>")
.AppendFormat(" /// 获取{0}。", dataTableProcessor.GetComment(i)).AppendLine()
.AppendLine(" /// </summary>")
.AppendFormat(" public {0} {1}", dataTableProcessor.GetLanguageKeyword(i), dataTableProcessor.GetName(i)).AppendLine()
.AppendLine(" {")
.AppendLine(" get;")
.AppendLine(" private set;")
.Append(" }");
}

return stringBuilder.ToString();
}

private static string GenerateDataTableStringParser(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.AppendLine(" public override bool ParseDataRow(GameFrameworkSegment<string> dataRowSegment)")
.AppendLine(" {")
.AppendLine(" // Star Force 示例代码,正式项目使用时请调整此处的生成代码,以处理 GCAlloc 问题!")
.AppendLine(" string[] columnTexts = dataRowSegment.Source.Substring(dataRowSegment.Offset, dataRowSegment.Length).Split(DataTableExtension.DataSplitSeparator);")
.AppendLine(" for (int i = 0; i < columnTexts.Length; i++)")
.AppendLine(" {")
.AppendLine(" columnTexts[i] = columnTexts[i].Trim(DataTableExtension.DataTrimSeparator);")
.AppendLine(" }")
.AppendLine()
.AppendLine(" int index = 0;");

for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
stringBuilder.AppendLine(" index++;");
continue;
}

if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
stringBuilder.AppendLine(" m_Id = int.Parse(columnTexts[index++]);");
continue;
}

if (dataTableProcessor.IsSystem(i))
{
string languageKeyword = dataTableProcessor.GetLanguageKeyword(i);
if (languageKeyword == "string")
{
stringBuilder.AppendFormat(" {0} = columnTexts[index++];", dataTableProcessor.GetName(i)).AppendLine();
}
else
{
stringBuilder.AppendFormat(" {0} = {1}.Parse(columnTexts[index++]);", dataTableProcessor.GetName(i), languageKeyword).AppendLine();
}
}
else
{
stringBuilder.AppendFormat(" {0} = DataTableExtension.Parse{1}(columnTexts[index++]);", dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
}
}

stringBuilder
.AppendLine()
.AppendLine(" GeneratePropertyArray();")
.AppendLine(" return true;")
.Append(" }");

return stringBuilder.ToString();
}

private static string GenerateDataTableBytesParser(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.AppendLine(" public override bool ParseDataRow(GameFrameworkSegment<byte[]> dataRowSegment)")
.AppendLine(" {")
.AppendLine(" // Star Force 示例代码,正式项目使用时请调整此处的生成代码,以处理 GCAlloc 问题!")
.AppendLine(" string[] columnTexts = dataRowSegment.Source.Substring(dataRowSegment.Offset, dataRowSegment.Length).Split(DataTableExtension.DataSplitSeparator);")
.AppendLine(" for (int i = 0; i < columnTexts.Length; i++)")
.AppendLine(" {")
.AppendLine(" columnTexts[i] = columnTexts[i].Trim(DataTableExtension.DataTrimSeparator);")
.AppendLine(" }")
.AppendLine()
.AppendLine(" int index = 0;");

for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
continue;
}

if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
stringBuilder.AppendLine(" m_Id = binaryReader.ReadInt32();");
continue;
}

stringBuilder.AppendFormat(" {0} = binaryReader.Read{1}();", dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
}

stringBuilder
.AppendLine(" }")
.AppendLine(" }")
.AppendLine()
.AppendLine(" GeneratePropertyArray();")
.AppendLine(" return true;")
.Append(" }");

return stringBuilder.ToString();
}

private static string GenerateDataTableStreamParser(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.AppendLine(" public override bool ParseDataRow(GameFrameworkSegment<Stream> dataRowSegment)")
.AppendLine(" {")
.AppendLine(" Log.Warning(\"Not implemented ParseDataRow(GameFrameworkSegment<Stream>)\");")
.AppendLine(" return false;")
.Append(" }");

return stringBuilder.ToString();
}

private static string GenerateDataTablePropertyArray(DataTableProcessor dataTableProcessor)
{
List<PropertyCollection> propertyCollections = new List<PropertyCollection>();
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
continue;
}

if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
continue;
}

string name = dataTableProcessor.GetName(i);
if (!EndWithNumberRegex.IsMatch(name))
{
continue;
}

string propertyCollectionName = EndWithNumberRegex.Replace(name, string.Empty);
int id = int.Parse(EndWithNumberRegex.Match(name).Value);

PropertyCollection propertyCollection = null;
foreach (PropertyCollection pc in propertyCollections)
{
if (pc.Name == propertyCollectionName)
{
propertyCollection = pc;
break;
}
}

if (propertyCollection == null)
{
propertyCollection = new PropertyCollection(propertyCollectionName, dataTableProcessor.GetLanguageKeyword(i));
propertyCollections.Add(propertyCollection);
}

propertyCollection.AddItem(id, name);
}

StringBuilder stringBuilder = new StringBuilder();
bool firstProperty = true;
foreach (PropertyCollection propertyCollection in propertyCollections)
{
if (firstProperty)
{
firstProperty = false;
}
else
{
stringBuilder.AppendLine().AppendLine();
}

stringBuilder
.AppendFormat(" private KeyValuePair<int, {1}>[] m_{0} = null;", propertyCollection.Name, propertyCollection.LanguageKeyword).AppendLine()
.AppendLine()
.AppendFormat(" public int Get{0}(int id)", propertyCollection.Name).AppendLine()
.AppendLine(" {")
.AppendFormat(" foreach (KeyValuePair<int, {1}> i in m_{0})", propertyCollection.Name, propertyCollection.LanguageKeyword).AppendLine()
.AppendLine(" {")
.AppendLine(" if (i.Key == id)")
.AppendLine(" {")
.AppendLine(" return i.Value;")
.AppendLine(" }")
.AppendLine(" }")
.AppendLine()
.AppendFormat(" throw new GameFrameworkException(Utility.Text.Format(\"Get{0} with invalid id '{{0}}'.\", id.ToString()));", propertyCollection.Name).AppendLine()
.AppendLine(" }")
.AppendLine()
.AppendFormat(" public int Get{0}At(int index)", propertyCollection.Name).AppendLine()
.AppendLine(" {")
.AppendFormat(" if (index < 0 || index >= m_{0}.Length)", propertyCollection.Name).AppendLine()
.AppendLine(" {")
.AppendFormat(" throw new GameFrameworkException(Utility.Text.Format(\"Get{0}At with invalid index '{{0}}'.\", index.ToString()));", propertyCollection.Name).AppendLine()
.AppendLine(" }")
.AppendLine()
.AppendFormat(" return m_{0}[index].Value;", propertyCollection.Name).AppendLine()
.Append(" }");
}

if (propertyCollections.Count > 0)
{
stringBuilder.AppendLine().AppendLine();
}

stringBuilder
.AppendLine(" private void GeneratePropertyArray()")
.AppendLine(" {");

firstProperty = true;
foreach (PropertyCollection propertyCollection in propertyCollections)
{
if (firstProperty)
{
firstProperty = false;
}
else
{
stringBuilder.AppendLine().AppendLine();
}

stringBuilder
.AppendFormat(" m_{0} = new KeyValuePair<int, {1}>[]", propertyCollection.Name, propertyCollection.LanguageKeyword).AppendLine()
.AppendLine(" {");

int itemCount = propertyCollection.ItemCount;
for (int i = 0; i < itemCount; i++)
{
KeyValuePair<int, string> item = propertyCollection.GetItem(i);
stringBuilder.AppendFormat(" new KeyValuePair<int, {0}>({1}, {2}),", propertyCollection.LanguageKeyword, item.Key.ToString(), item.Value).AppendLine();
}

stringBuilder.Append(" };");
}

stringBuilder
.AppendLine()
.Append(" }");

return stringBuilder.ToString();
}

private sealed class PropertyCollection
{
private readonly string m_Name;
private readonly string m_LanguageKeyword;
private readonly List<KeyValuePair<int, string>> m_Items;

public PropertyCollection(string name, string languageKeyword)
{
m_Name = name;
m_LanguageKeyword = languageKeyword;
m_Items = new List<KeyValuePair<int, string>>();
}

public string Name
{
get
{
return m_Name;
}
}

public string LanguageKeyword
{
get
{
return m_LanguageKeyword;
}
}

public int ItemCount
{
get
{
return m_Items.Count;
}
}

public KeyValuePair<int, string> GetItem(int index)
{
if (index < 0 || index >= m_Items.Count)
{
throw new GameFrameworkException(Utility.Text.Format("GetItem with invalid index '{0}'.", index.ToString()));
}

return m_Items[index];
}

public void AddItem(int id, string propertyName)
{
m_Items.Add(new KeyValuePair<int, string>(id, propertyName));
}
}
}
}
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
 //------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年2月10日
//------------------------------------------------------------

using Assets.GameMain.Scripts.Procedure;
using GameFramework;
using UnityEditor;
using UnityEngine;
using UnityGameFramework.Editor.DataTableTools;

namespace Assets.GameMain.Scripts.DataTable.DataTableGenerator
{
public class DataTableGeneratorMenu
{
[MenuItem("DataTableTools/Generate DataTables")]
private static void GenerateDataTables()
{
//所要生成的CSharp类取决于ProcedurePreload.DataTableNames(自己视情况改变)
foreach (string dataTableName in ProcedurePreload.DataTableNames)
{
DataTableProcessor dataTableProcessor = DataTableGenerator.CreateDataTableProcessor(dataTableName);
if (!DataTableGenerator.CheckRawData(dataTableProcessor, dataTableName))
{
Debug.LogError(Utility.Text.Format("Check raw data failure. DataTableName='{0}'", dataTableName));
return;
}

DataTableGenerator.GenerateDataFile(dataTableProcessor, dataTableName);
DataTableGenerator.GenerateCodeFile(dataTableProcessor, dataTableName);
}

AssetDatabase.Refresh();
}
}
}
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
50
51
52
53
54
 //------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年2月10日
//------------------------------------------------------------

using System;
using UnityEngine;
using System.IO;
namespace Assets.GameMain.Scripts.DataTable
{
public static class BinaryReaderExtension
{
public static Color32 ReadColor32(this BinaryReader binaryReader)
{
return new Color32(binaryReader.ReadByte(), binaryReader.ReadByte(), binaryReader.ReadByte(), binaryReader.ReadByte());
}

public static Color ReadColor(this BinaryReader binaryReader)
{
return new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}

public static DateTime ReadDateTime(this BinaryReader binaryReader)
{
return new DateTime(binaryReader.ReadInt64());
}

public static Quaternion ReadQuaternion(this BinaryReader binaryReader)
{
return new Quaternion(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}

public static Rect ReadRect(this BinaryReader binaryReader)
{
return new Rect(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}

public static Vector2 ReadVector2(this BinaryReader binaryReader)
{
return new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
}

public static Vector3 ReadVector3(this BinaryReader binaryReader)
{
return new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}

public static Vector4 ReadVector4(this BinaryReader binaryReader)
{
return new Vector4(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
}
}
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
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
 //------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年1月12日 20:56:31
//------------------------------------------------------------

using GameFramework;
using System;
using Assets.GameMain.Scripts.Definition.Constant;
using GameMain;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace Assets.GameMain.Scripts.DataTable
{
public static class DataTableExtension
{
//CSharp类的前置命名空间
private const string DataRowClassPrefixName = "Assets.GameMain.Scripts.DataTable.DR";
internal const char DataSplitSeparator = '\t';
internal const char DataTrimSeparator = '\"';

public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName,
LoadType loadType, object userData = null)
{
if (string.IsNullOrEmpty(dataTableName))
{
Log.Warning("Data table name is invalid.");
return;
}

string[] splitNames = dataTableName.Split('_');
if (splitNames.Length > 2)
{
Log.Warning("Data table name is invalid.");
return;
}

string dataRowClassName = DataRowClassPrefixName + splitNames[0];

Type dataRowType = Type.GetType(dataRowClassName);
if (dataRowType == null)
{
Log.Warning("Can not get data row type with class name '{0}'.", dataRowClassName);
return;
}

string dataTableNameInType = splitNames.Length > 1 ? splitNames[1] : null;
dataTableComponent.LoadDataTable(dataRowType, dataTableName, dataTableNameInType,
AssetUtility.GetDataTableAsset(dataTableName, loadType), loadType,
Constant.AssetPriority.DataTableAsset, userData);
}

public static Color32 ParseColor32(string value)
{
string[] splitValue = value.Split(',');
return new Color32(byte.Parse(splitValue[0]), byte.Parse(splitValue[1]), byte.Parse(splitValue[2]),
byte.Parse(splitValue[3]));
}

public static Color ParseColor(string value)
{
string[] splitValue = value.Split(',');
return new Color(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}

public static Quaternion ParseQuaternion(string value)
{
string[] splitValue = value.Split(',');
return new Quaternion(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}

public static Rect ParseRect(string value)
{
string[] splitValue = value.Split(',');
return new Rect(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}

public static Vector2 ParseVector2(string value)
{
string[] splitValue = value.Split(',');
return new Vector2(float.Parse(splitValue[0]), float.Parse(splitValue[1]));
}

public static Vector3 ParseVector3(string value)
{
string[] splitValue = value.Split(',');
return new Vector3(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]));
}

public static Vector4 ParseVector4(string value)
{
string[] splitValue = value.Split(',');
return new Vector4(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}
}
}