@@ -14,6 +14,7 @@ public class ProtocolHelper
1414 {
1515 static List < Type > ModuleList = new List < Type > ( ) ;
1616 static List < Type > msgList = new List < Type > ( ) ;
17+ static List < Type > StructList = new List < Type > ( ) ;
1718
1819 public const string PathName = "ProtocolGenerate" ;
1920 const string AnalysisCodeName = "ProtocolAnalysisService" ;
@@ -34,6 +35,8 @@ static void StartGenerate()
3435 string protocolContent = GeneratePrototalContent ( ) ;
3536 string protocolList = GeneratePrototalList ( ) ;
3637
38+ Debug . Log ( protocolContent ) ;
39+
3740 string ProtocolSavePath = Application . dataPath + "/Resources/Network/" + ProtocolService . c_ProtocolFileName + ".txt" ;
3841 ResourceIOTool . WriteStringByFile ( ProtocolSavePath , protocolContent ) ;
3942
@@ -146,7 +149,7 @@ static string GenerateProtocolMessageField(FieldInfo field, ref int count)
146149 }
147150 else if ( field . FieldType . Name == typeof ( List < > ) . Name )
148151 {
149- string content = "repeated" ;
152+ string content = "repeated " ;
150153 Type type = field . FieldType . GetGenericArguments ( ) [ 0 ] ;
151154
152155 content += GetTypeName ( type ) + " " + GenerateProtocolFieldName ( field ) + " = " + count ++ + ";\n " ;
@@ -189,7 +192,7 @@ static string GetTypeName(Type type)
189192 {
190193 return "int8" ;
191194 }
192- else if ( type . IsSubclassOf ( typeof ( Enum ) ) )
195+ else if ( type == typeof ( string ) )
193196 {
194197 return "string" ;
195198 }
@@ -312,6 +315,9 @@ static void GenerateProtocolToCsharp()
312315 else
313316 {
314317 string className = GetMessageNmae ( item . Value ) ;
318+
319+ //Debug.Log(className + " -> " + item.Value);
320+
315321 if ( GetAimType ( className ) == null )
316322 {
317323 string name = "m_" + item . Value + "_c" ;
@@ -356,7 +362,14 @@ static void GenerateProtocolToCsharp()
356362 output += GetTab ( 1 ) + "#region Struct\n " ;
357363 for ( int i = 0 ; i < s_SubStruct . Count ; i ++ )
358364 {
359- output += GenerateProtocolClass ( 2 , SendMode . Both , null , s_SubStruct [ i ] , protocolInfo [ s_SubStruct [ i ] ] , true ) ;
365+ try
366+ {
367+ output += GenerateProtocolClass ( 2 , SendMode . Both , null , s_SubStruct [ i ] , protocolInfo [ s_SubStruct [ i ] ] , true ) ;
368+ }
369+ catch
370+ {
371+ throw new Exception ( "s_SubStruct[i] ->" + s_SubStruct [ i ] ) ;
372+ }
360373 }
361374 output += GetTab ( 1 ) + "#endregion \n " ;
362375
@@ -401,7 +414,7 @@ static string GenerateProtocolClass(int tab,SendMode mode,string ModuleName, str
401414
402415 if ( isStruct )
403416 {
404- content = GetTab ( tab ) + "public class " + ClassName + " \n " ;
417+ content = GetTab ( tab ) + "public class " + ClassName + " : IProtocolStructInterface \n " ;
405418 }
406419 else
407420 {
@@ -567,6 +580,11 @@ static string GetMessageNmae(string name)
567580 }
568581 }
569582
583+ if ( result == "" )
584+ {
585+ return name ;
586+ }
587+
570588 return result ;
571589 }
572590
@@ -614,6 +632,16 @@ static void GenerateList()
614632
615633 //进行排序
616634 msgList . Sort ( sort ) ;
635+
636+ StructList . Clear ( ) ;
637+
638+ for ( int i = 0 ; i < types . Length ; i ++ )
639+ {
640+ if ( typeof ( IProtocolStructInterface ) . IsAssignableFrom ( types [ i ] ) )
641+ {
642+ StructList . Add ( types [ i ] ) ;
643+ }
644+ }
617645 }
618646
619647 static string GenerateCSharpContent ( )
@@ -808,6 +836,14 @@ static string GeneratePrototalContent()
808836 content += "\n " ;
809837 }
810838
839+ Debug . Log ( "StructList " + StructList . Count ) ;
840+
841+ for ( int i = 0 ; i < StructList . Count ; i ++ )
842+ {
843+ content += "message " + GenerateProtocolName ( StructList [ i ] ) + "\n " ;
844+ content += GenerateProtocolMessageNoHead ( StructList [ i ] ) ;
845+ }
846+
811847 return content ;
812848 }
813849
0 commit comments