|
|
@@ -23,9 +23,9 @@ namespace MyEditor
|
|
|
public class Proto2CSEditor : EditorWindow
|
|
|
{
|
|
|
private const string protoPath = @"..\Proto\";
|
|
|
- private const string innerOutPath = @"..\Server\Model\Module\Message\";
|
|
|
- private const string outerOutPath = @"Assets\Scripts\Module\Message\";
|
|
|
- private const string hotfixOutPath = @"Hotfix\Module\Message\";
|
|
|
+ private const string serverMessagePath = @"..\Server\Model\Module\Message\";
|
|
|
+ private const string clientMessagePath = @"Assets\Scripts\Module\Message\";
|
|
|
+ private const string hotfixMessagePath = @"Hotfix\Module\Message\";
|
|
|
private static readonly char[] splitChars = { ' ', '\t' };
|
|
|
private static readonly List<OpcodeInfo> msgOpcode = new List<OpcodeInfo>();
|
|
|
private static MultiMap<string, string> parentMsg = new MultiMap<string, string>();
|
|
|
@@ -34,21 +34,28 @@ namespace MyEditor
|
|
|
public static void AllProto2CS()
|
|
|
{
|
|
|
msgOpcode.Clear();
|
|
|
- Proto2CS("ETModel", "OuterMessage.proto", outerOutPath, "OuterOpcode", 100, HeadFlag.Proto | HeadFlag.Bson);
|
|
|
- GenerateOpcode("OuterOpcode", outerOutPath);
|
|
|
+ Proto2CS("ETModel", "OuterMessage.proto", clientMessagePath, "OuterOpcode", 100, HeadFlag.Proto | HeadFlag.Bson);
|
|
|
+ GenerateOpcode("OuterOpcode", clientMessagePath);
|
|
|
+
|
|
|
+ Proto2CS("ETModel", "OuterMessage.proto", serverMessagePath, "OuterOpcode", 100, HeadFlag.Proto | HeadFlag.Bson, false);
|
|
|
+ GenerateOpcode("OuterOpcode", serverMessagePath);
|
|
|
|
|
|
msgOpcode.Clear();
|
|
|
- Proto2CS("ETModel", "InnerMessage.proto", innerOutPath, "InnerOpcode", 1000, HeadFlag.Bson);
|
|
|
- GenerateOpcode("InnerOpcode", innerOutPath);
|
|
|
+ Proto2CS("ETHotfix", "HotfixMessage.proto", hotfixMessagePath, "HotfixOpcode", 10000, HeadFlag.Bson);
|
|
|
+ GenerateOpcode("HotfixOpcode", hotfixMessagePath);
|
|
|
|
|
|
msgOpcode.Clear();
|
|
|
- Proto2CS("ETHotfix", "HotfixMessage.proto", hotfixOutPath, "HotfixOpcode", 10000, HeadFlag.Bson);
|
|
|
- GenerateOpcode("HotfixOpcode", hotfixOutPath);
|
|
|
-
|
|
|
+ Proto2CS("ETModel", "HotfixMessage.proto", serverMessagePath, "HotfixOpcode", 10000, HeadFlag.Bson, false);
|
|
|
+ GenerateOpcode("HotfixOpcode", serverMessagePath);
|
|
|
+
|
|
|
+ msgOpcode.Clear();
|
|
|
+ Proto2CS("ETModel", "InnerMessage.proto", serverMessagePath, "InnerOpcode", 1000, HeadFlag.Bson, false);
|
|
|
+ GenerateOpcode("InnerOpcode", serverMessagePath);
|
|
|
+
|
|
|
AssetDatabase.Refresh();
|
|
|
}
|
|
|
|
|
|
- public static void Proto2CS(string ns, string protoName, string outputPath, string opcodeClassName, int startOpcode, HeadFlag flag)
|
|
|
+ public static void Proto2CS(string ns, string protoName, string outputPath, string opcodeClassName, int startOpcode, HeadFlag flag, bool isClient = true)
|
|
|
{
|
|
|
msgOpcode.Clear();
|
|
|
parentMsg = new MultiMap<string, string>();
|
|
|
@@ -60,11 +67,6 @@ namespace MyEditor
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.Append("using ProtoBuf;\n");
|
|
|
sb.Append("using ETModel;\n");
|
|
|
- if (ns == "ETHotfix")
|
|
|
- {
|
|
|
- sb.Append("using ETHotfix;\n");
|
|
|
- }
|
|
|
-
|
|
|
sb.Append("using System.Collections.Generic;\n");
|
|
|
sb.Append("using MongoDB.Bson.Serialization.Attributes;\n");
|
|
|
sb.Append($"namespace {ns}\n");
|
|
|
@@ -150,7 +152,7 @@ namespace MyEditor
|
|
|
|
|
|
if (newline.StartsWith("repeated"))
|
|
|
{
|
|
|
- Repeated(sb, newline);
|
|
|
+ Repeated(sb, ns, newline, isClient);
|
|
|
}
|
|
|
|
|
|
if (isMsgStart && newline == "}")
|
|
|
@@ -161,15 +163,18 @@ namespace MyEditor
|
|
|
}
|
|
|
sb.Append("}\n");
|
|
|
|
|
|
- GenerateHead(sb, flag, opcodeClassName);
|
|
|
+ if (!isClient)
|
|
|
+ {
|
|
|
+ GenerateHead(sb, ns, flag, opcodeClassName);
|
|
|
+ }
|
|
|
|
|
|
File.WriteAllText(csPath, sb.ToString());
|
|
|
}
|
|
|
|
|
|
- private static void GenerateHead(StringBuilder sb, HeadFlag flag, string opcodeClassName)
|
|
|
+ private static void GenerateHead(StringBuilder sb, string ns, HeadFlag flag, string opcodeClassName)
|
|
|
{
|
|
|
- sb.AppendLine("#if SERVER");
|
|
|
- sb.AppendLine("namespace ETModel\n{");
|
|
|
+ sb.AppendLine($"namespace {ns}");
|
|
|
+ sb.AppendLine("{");
|
|
|
foreach (string parentClass in parentMsg.GetDictionary().Keys)
|
|
|
{
|
|
|
if ((flag & HeadFlag.Bson) != 0)
|
|
|
@@ -181,22 +186,6 @@ namespace MyEditor
|
|
|
}
|
|
|
|
|
|
|
|
|
- sb.Append($"\tpublic partial class {parentClass} {{}}\n\n");
|
|
|
- }
|
|
|
- sb.AppendLine("}");
|
|
|
- sb.AppendLine("#endif");
|
|
|
-
|
|
|
- sb.AppendLine("namespace ETModel\n{");
|
|
|
- foreach (string parentClass in parentMsg.GetDictionary().Keys)
|
|
|
- {
|
|
|
- if ((flag & HeadFlag.Proto) != 0)
|
|
|
- {
|
|
|
- foreach (string s in parentMsg.GetAll(parentClass))
|
|
|
- {
|
|
|
- sb.Append($"\t[ProtoInclude({opcodeClassName}.{s}, typeof({s}))]\n");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
sb.Append($"\tpublic partial class {parentClass} {{}}\n\n");
|
|
|
}
|
|
|
sb.AppendLine("}");
|
|
|
@@ -220,7 +209,7 @@ namespace MyEditor
|
|
|
File.WriteAllText(csPath, sb.ToString());
|
|
|
}
|
|
|
|
|
|
- private static void Repeated(StringBuilder sb, string newline)
|
|
|
+ private static void Repeated(StringBuilder sb, string ns, string newline, bool isClient)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
@@ -231,7 +220,15 @@ namespace MyEditor
|
|
|
type = ConvertType(type);
|
|
|
string name = ss[2];
|
|
|
int order = int.Parse(ss[4]);
|
|
|
- sb.Append($"\t\t[ProtoMember({order})]\n");
|
|
|
+ if (isClient)
|
|
|
+ {
|
|
|
+ sb.Append($"\t\t[ProtoMember({order}, TypeName = \"{ns}.{type}\")]\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sb.Append($"\t\t[ProtoMember({order})]\n");
|
|
|
+ }
|
|
|
+
|
|
|
sb.Append($"\t\tpublic List<{type}> {name} = new List<{type}>();\n\n");
|
|
|
}
|
|
|
catch (Exception e)
|