Skip to content

Commit 2123f97

Browse files
committed
修复BUG
1 parent 1365c7e commit 2123f97

File tree

3 files changed

+127
-15
lines changed

3 files changed

+127
-15
lines changed

Assets/Script/Core/Editor/Network/Protocol/ProtocolHelper.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,21 @@ static string GenerateProtocolMessageField(FieldInfo field, ref int count)
153153
string content = "repeated ";
154154
Type type = field.FieldType.GetGenericArguments()[0];
155155

156-
content += GetTypeName(type) + " " + GenerateProtocolFieldName(field) + " = " + count++ + ";\n";
156+
content += GetTypeName(type).ToLower() + " " + GenerateProtocolFieldName(field) + " = " + count++ + ";\n";
157157

158158
return content;
159159
}
160+
else if (field.FieldType == typeof(string))
161+
{
162+
return "required string " + GenerateProtocolFieldName(field) + " = " + count++ + ";\n";
163+
}
160164

161165
else
162166
{
163-
return "required string " + GenerateProtocolFieldName(field) + " = " + count++ + ";\n";
167+
string content = "required ";
168+
content += GetTypeName(field.FieldType).ToLower() + " " + GenerateProtocolFieldName(field) + " = " + count++ + ";\n";
169+
170+
return content;
164171
}
165172
}
166173

@@ -367,9 +374,9 @@ static void GenerateProtocolToCsharp()
367374
{
368375
output += GenerateProtocolClass(2, SendMode.Both, null, s_SubStruct[i], protocolInfo[s_SubStruct[i]], true);
369376
}
370-
catch
377+
catch(Exception e)
371378
{
372-
throw new Exception("s_SubStruct[i] ->" + s_SubStruct[i]);
379+
throw new Exception("s_SubStruct[i] ->" + s_SubStruct[i] + "\n" + e.ToString());
373380
}
374381
}
375382
output += GetTab(1) + "#endregion \n";
@@ -637,7 +644,8 @@ static void GenerateList()
637644

638645
for (int i = 0; i < types.Length; i++)
639646
{
640-
if (typeof(IProtocolStructInterface).IsAssignableFrom(types[i]))
647+
if (typeof(IProtocolStructInterface).IsAssignableFrom(types[i])
648+
&& types[i] != typeof(IProtocolStructInterface))
641649
{
642650
StructList.Add(types[i]);
643651
}
@@ -800,8 +808,7 @@ static string GeneratePrototalList()
800808

801809
for (int j = 0; j < msgList.Count; j++)
802810
{
803-
if (msgList[j].IsSubclassOf(ModuleList[i]) ||
804-
ModuleList[i].IsAssignableFrom(msgList[i]))
811+
if (msgList[j].IsSubclassOf(ModuleList[i]))
805812
{
806813
string nameTmp = GenerateProtocolName(msgList[j]);
807814
if(!nameList.Contains(nameTmp))
@@ -990,7 +997,7 @@ static string GenerateSerializeFieldContent(int tab, FieldInfo field, string aim
990997
{
991998
content += GetTab(tab) + "{\n";
992999

993-
content += GetTab(tab + 1) + "List<" + typeTmp + "> list = new List<" + typeTmp + ">();\n";
1000+
content += GetTab(tab + 1) + "List<object> list = new List<object>();\n";
9941001
content += GetTab(tab + 1) + "for(int i = 0;i <" + sourceName + "." + field.Name + ".Count ; i++)\n";
9951002

9961003
content += GetTab(tab + 1) + "{\n";
@@ -1004,7 +1011,7 @@ static string GenerateSerializeFieldContent(int tab, FieldInfo field, string aim
10041011
{
10051012
content += GetTab(tab) + "{\n";
10061013

1007-
content += GetTab(tab + 1) + "List<Dictionary<string, object>> list" + tab + " = new List<Dictionary<string, object>>();\n";
1014+
content += GetTab(tab + 1) + "List<object> list" + tab + " = new List<object>();\n";
10081015
content += GetTab(tab + 1) + "for(int i" + tab + " = 0;i" + tab + " <" + sourceName + "." + field.Name + ".Count ; i" + tab + "++)\n";
10091016

10101017
content += GetTab(tab + 1) + "{\n";
@@ -1117,8 +1124,9 @@ static string GenerateAnalysisContent(int tab, FieldInfo field, string aimName,s
11171124
else
11181125
{
11191126
content += GetTab(tab) + "{\n";
1120-
content += GenerateAnalysisClassContent(tab + 1 , field.FieldType, "tmp" + tab + "", sourceName);
1121-
1127+
content += GetTab(tab + 1) + "Dictionary<string, object> data" + tab + " = (Dictionary<string, object>)" + sourceName + "[\"" + GenerateProtocolFieldName(field) + "\"];\n";
1128+
content += GenerateAnalysisClassContent(tab + 1, field.FieldType, "tmp" + tab + "", "data" + tab);
1129+
11221130
content += GetTab(tab + 1) + aimName + "." + field.Name + " = " + "tmp" + tab + ";\n";
11231131

11241132
content += GetTab(tab) + "}\n";
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
[ExecuteInEditMode]
7+
public class BatchReplaceNameTool : EditorWindow
8+
{
9+
10+
[MenuItem("Tools/批量修改名称")]
11+
12+
public static void ShowWindow()
13+
{
14+
GetWindow(typeof(BatchReplaceNameTool));
15+
}
16+
17+
string m_content = "";
18+
string m_replace = "";
19+
Object[] selects;
20+
Vector3 pos = Vector3.zero;
21+
22+
Vector3 pos2 = Vector3.zero;
23+
24+
void OnGUI()
25+
{
26+
titleContent.text = "批量修改名称";
27+
28+
pos = GUILayout.BeginScrollView(pos);
29+
30+
EditorGUILayout.LabelField("已选列表:");
31+
EditorGUI.indentLevel++;
32+
33+
for (int i = 0; i < selects.Length; i++)
34+
{
35+
EditorGUILayout.ObjectField(selects[i], typeof(Object));
36+
}
37+
38+
EditorGUI.indentLevel--;
39+
GUILayout.EndScrollView();
40+
EditorGUILayout.Space();
41+
42+
m_content = EditorGUILayout.TextField("replace content:", m_content);
43+
m_replace = EditorGUILayout.TextField("replace to:", m_replace);
44+
45+
EditorGUILayout.Space();
46+
47+
if(m_content != "")
48+
{
49+
EditorGUILayout.LabelField("预览:");
50+
EditorGUI.indentLevel++;
51+
52+
pos2 = GUILayout.BeginScrollView(pos2);
53+
54+
for (int i = 0; i < selects.Length; i++)
55+
{
56+
string tmp = selects[i].name;
57+
58+
tmp = tmp.Replace(m_content, m_replace);
59+
60+
EditorGUILayout.LabelField(tmp);
61+
}
62+
GUILayout.EndScrollView();
63+
EditorGUI.indentLevel--;
64+
65+
if (GUILayout.Button("Repalce!"))
66+
{
67+
ChangeName(selects, m_content, m_replace);
68+
}
69+
}
70+
}
71+
72+
private void Update()
73+
{
74+
selects = Selection.GetFiltered(typeof(GameObject), SelectionMode.Unfiltered);
75+
EnterLogic(selects, m_content);
76+
77+
Repaint();
78+
}
79+
80+
void EnterLogic(Object[] objs, string newName)
81+
{
82+
if (Input.GetKeyDown(KeyCode.A))
83+
{
84+
Debug.Log("Enter");
85+
ChangeName(objs, newName, m_replace);
86+
}
87+
}
88+
89+
void ChangeName(Object[] objs, string newName,string replaceTo)
90+
{
91+
Undo.RecordObjects(objs, "ReplaceName->" + newName);
92+
for (int i = 0; i < objs.Length; i++)
93+
{
94+
string tmp = objs[i].name;
95+
96+
tmp = tmp.Replace(newName, replaceTo);
97+
objs[i].name = tmp;
98+
}
99+
}
100+
}

Assets/Script/Core/Network/Protocol/ProtocolService.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ void SpiltMessage(byte[] bytes,int length)
251251
WriteBytes(bytes, length);
252252
int i = 0;
253253

254-
Debug.Log("SpiltMessage " + length);
255-
256254
while (GetBufferLength() != 0 && ReadLength() <= GetBufferLength())
257255
{
258256
ReceiveDataLoad(ReadByte(ReadLength()));
@@ -803,6 +801,7 @@ private Dictionary<string, object> ReadDictionary(string dictName, ByteArray ba)
803801

804802
if (st_len == 0)
805803
{
804+
Debug.Log("return");
806805
return tbl;
807806
}
808807

@@ -915,6 +914,8 @@ private List<Dictionary<string, object>> ReadDictionaryList(string str, ByteArra
915914
int len1 = ba.ReadUShort();
916915
ba.ReadUInt();
917916

917+
//Debug.Log("len1 " + len1 + " " + ba.ReadUInt());
918+
918919
for (int i = 0; i < len1; i++)
919920
{
920921
stbl.Add(ReadDictionary(str, ba));
@@ -1128,10 +1129,13 @@ private List<byte> GetCustomTypeByte(string customType, Dictionary<string, objec
11281129
{
11291130
if (data.ContainsKey(fieldName))
11301131
{
1132+
customType = (string)currentField["vp"];
11311133
if (repeatType == RT_equired)
11321134
{
1133-
customType = (string)currentField["vp"];
1134-
Bytes.bytes.AddRange(GetSendByte(customType, (Dictionary<string, object>)data[fieldName]));
1135+
List<byte> byteTmp = GetCustomTypeByte(customType, (Dictionary<string, object>)data[fieldName]);
1136+
1137+
Bytes.WriteInt(byteTmp.Count);
1138+
Bytes.bytes.AddRange(byteTmp);
11351139
}
11361140
else
11371141
{

0 commit comments

Comments
 (0)