Browse Source

协议里使用List代替Dictionary,避免Bson序列化报错

大爷 2 years ago
parent
commit
6cefcee364

+ 7 - 1
Unity/Assets/Config/Proto/OuterMessage_C_10001.proto

@@ -64,6 +64,12 @@ message MoveInfo
 	int32 TurnSpeed = 3;
 }
 
+message IntKV
+{
+	int32 Key = 1;
+	int64 Value = 2;
+}
+
 message UnitInfo
 {
 	int64 UnitId = 1;
@@ -71,7 +77,7 @@ message UnitInfo
 	int32 Type = 3;
 	Unity.Mathematics.float3 Position = 4;
 	Unity.Mathematics.float3 Forward = 5;
-	map<int32, int64> KV = 6;
+	repeated IntKV KV = 6;
 	MoveInfo MoveInfo = 7;
 }
 

+ 5 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/Unit/UnitHelper.cs

@@ -32,11 +32,14 @@ namespace ET.Server
                 }
             }
 
-            unitInfo.KV = new Dictionary<int, long>();
+            unitInfo.KV = new List<IntKV>();
 
             foreach ((int key, long value) in nc.NumericDic)
             {
-                unitInfo.KV.Add(key, value);
+                var kv = new IntKV();
+                kv.Key = key;
+                kv.Value = value;
+                unitInfo.KV.Add(kv);
             }
 
             return unitInfo;

+ 40 - 27
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs

@@ -130,6 +130,18 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.IntKV)]
+	[ProtoContract]
+	public partial class IntKV: ProtoObject
+	{
+		[ProtoMember(1)]
+		public int Key { get; set; }
+
+		[ProtoMember(2)]
+		public long Value { get; set; }
+
+	}
+
 	[Message(OuterMessage.UnitInfo)]
 	[ProtoContract]
 	public partial class UnitInfo: ProtoObject
@@ -149,9 +161,9 @@ namespace ET
 		[ProtoMember(5)]
 		public Unity.Mathematics.float3 Forward { get; set; }
 
-		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(6)]
-		public Dictionary<int, long> KV { get; set; }
+		public List<IntKV> KV { get; set; }
+
 		[ProtoMember(7)]
 		public MoveInfo MoveInfo { get; set; }
 
@@ -490,30 +502,31 @@ namespace ET
 		 public const ushort C2G_EnterMap = 10008;
 		 public const ushort G2C_EnterMap = 10009;
 		 public const ushort MoveInfo = 10010;
-		 public const ushort UnitInfo = 10011;
-		 public const ushort M2C_CreateUnits = 10012;
-		 public const ushort M2C_CreateMyUnit = 10013;
-		 public const ushort M2C_StartSceneChange = 10014;
-		 public const ushort M2C_RemoveUnits = 10015;
-		 public const ushort C2M_PathfindingResult = 10016;
-		 public const ushort C2M_Stop = 10017;
-		 public const ushort M2C_PathfindingResult = 10018;
-		 public const ushort M2C_Stop = 10019;
-		 public const ushort C2G_Ping = 10020;
-		 public const ushort G2C_Ping = 10021;
-		 public const ushort G2C_Test = 10022;
-		 public const ushort C2M_Reload = 10023;
-		 public const ushort M2C_Reload = 10024;
-		 public const ushort C2R_Login = 10025;
-		 public const ushort R2C_Login = 10026;
-		 public const ushort C2G_LoginGate = 10027;
-		 public const ushort G2C_LoginGate = 10028;
-		 public const ushort G2C_TestHotfixMessage = 10029;
-		 public const ushort C2M_TestRobotCase = 10030;
-		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort IntKV = 10011;
+		 public const ushort UnitInfo = 10012;
+		 public const ushort M2C_CreateUnits = 10013;
+		 public const ushort M2C_CreateMyUnit = 10014;
+		 public const ushort M2C_StartSceneChange = 10015;
+		 public const ushort M2C_RemoveUnits = 10016;
+		 public const ushort C2M_PathfindingResult = 10017;
+		 public const ushort C2M_Stop = 10018;
+		 public const ushort M2C_PathfindingResult = 10019;
+		 public const ushort M2C_Stop = 10020;
+		 public const ushort C2G_Ping = 10021;
+		 public const ushort G2C_Ping = 10022;
+		 public const ushort G2C_Test = 10023;
+		 public const ushort C2M_Reload = 10024;
+		 public const ushort M2C_Reload = 10025;
+		 public const ushort C2R_Login = 10026;
+		 public const ushort R2C_Login = 10027;
+		 public const ushort C2G_LoginGate = 10028;
+		 public const ushort G2C_LoginGate = 10029;
+		 public const ushort G2C_TestHotfixMessage = 10030;
+		 public const ushort C2M_TestRobotCase = 10031;
+		 public const ushort M2C_TestRobotCase = 10032;
+		 public const ushort C2M_TransferMap = 10033;
+		 public const ushort M2C_TransferMap = 10034;
+		 public const ushort C2G_Benchmark = 10035;
+		 public const ushort G2C_Benchmark = 10036;
 	}
 }

+ 40 - 27
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs

@@ -130,6 +130,18 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.IntKV)]
+	[ProtoContract]
+	public partial class IntKV: ProtoObject
+	{
+		[ProtoMember(1)]
+		public int Key { get; set; }
+
+		[ProtoMember(2)]
+		public long Value { get; set; }
+
+	}
+
 	[Message(OuterMessage.UnitInfo)]
 	[ProtoContract]
 	public partial class UnitInfo: ProtoObject
@@ -149,9 +161,9 @@ namespace ET
 		[ProtoMember(5)]
 		public Unity.Mathematics.float3 Forward { get; set; }
 
-		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(6)]
-		public Dictionary<int, long> KV { get; set; }
+		public List<IntKV> KV { get; set; }
+
 		[ProtoMember(7)]
 		public MoveInfo MoveInfo { get; set; }
 
@@ -490,30 +502,31 @@ namespace ET
 		 public const ushort C2G_EnterMap = 10008;
 		 public const ushort G2C_EnterMap = 10009;
 		 public const ushort MoveInfo = 10010;
-		 public const ushort UnitInfo = 10011;
-		 public const ushort M2C_CreateUnits = 10012;
-		 public const ushort M2C_CreateMyUnit = 10013;
-		 public const ushort M2C_StartSceneChange = 10014;
-		 public const ushort M2C_RemoveUnits = 10015;
-		 public const ushort C2M_PathfindingResult = 10016;
-		 public const ushort C2M_Stop = 10017;
-		 public const ushort M2C_PathfindingResult = 10018;
-		 public const ushort M2C_Stop = 10019;
-		 public const ushort C2G_Ping = 10020;
-		 public const ushort G2C_Ping = 10021;
-		 public const ushort G2C_Test = 10022;
-		 public const ushort C2M_Reload = 10023;
-		 public const ushort M2C_Reload = 10024;
-		 public const ushort C2R_Login = 10025;
-		 public const ushort R2C_Login = 10026;
-		 public const ushort C2G_LoginGate = 10027;
-		 public const ushort G2C_LoginGate = 10028;
-		 public const ushort G2C_TestHotfixMessage = 10029;
-		 public const ushort C2M_TestRobotCase = 10030;
-		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort IntKV = 10011;
+		 public const ushort UnitInfo = 10012;
+		 public const ushort M2C_CreateUnits = 10013;
+		 public const ushort M2C_CreateMyUnit = 10014;
+		 public const ushort M2C_StartSceneChange = 10015;
+		 public const ushort M2C_RemoveUnits = 10016;
+		 public const ushort C2M_PathfindingResult = 10017;
+		 public const ushort C2M_Stop = 10018;
+		 public const ushort M2C_PathfindingResult = 10019;
+		 public const ushort M2C_Stop = 10020;
+		 public const ushort C2G_Ping = 10021;
+		 public const ushort G2C_Ping = 10022;
+		 public const ushort G2C_Test = 10023;
+		 public const ushort C2M_Reload = 10024;
+		 public const ushort M2C_Reload = 10025;
+		 public const ushort C2R_Login = 10026;
+		 public const ushort R2C_Login = 10027;
+		 public const ushort C2G_LoginGate = 10028;
+		 public const ushort G2C_LoginGate = 10029;
+		 public const ushort G2C_TestHotfixMessage = 10030;
+		 public const ushort C2M_TestRobotCase = 10031;
+		 public const ushort M2C_TestRobotCase = 10032;
+		 public const ushort C2M_TransferMap = 10033;
+		 public const ushort M2C_TransferMap = 10034;
+		 public const ushort C2G_Benchmark = 10035;
+		 public const ushort G2C_Benchmark = 10036;
 	}
 }

+ 40 - 27
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/OuterMessage_C_10001.cs

@@ -130,6 +130,18 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.IntKV)]
+	[ProtoContract]
+	public partial class IntKV: ProtoObject
+	{
+		[ProtoMember(1)]
+		public int Key { get; set; }
+
+		[ProtoMember(2)]
+		public long Value { get; set; }
+
+	}
+
 	[Message(OuterMessage.UnitInfo)]
 	[ProtoContract]
 	public partial class UnitInfo: ProtoObject
@@ -149,9 +161,9 @@ namespace ET
 		[ProtoMember(5)]
 		public Unity.Mathematics.float3 Forward { get; set; }
 
-		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(6)]
-		public Dictionary<int, long> KV { get; set; }
+		public List<IntKV> KV { get; set; }
+
 		[ProtoMember(7)]
 		public MoveInfo MoveInfo { get; set; }
 
@@ -490,30 +502,31 @@ namespace ET
 		 public const ushort C2G_EnterMap = 10008;
 		 public const ushort G2C_EnterMap = 10009;
 		 public const ushort MoveInfo = 10010;
-		 public const ushort UnitInfo = 10011;
-		 public const ushort M2C_CreateUnits = 10012;
-		 public const ushort M2C_CreateMyUnit = 10013;
-		 public const ushort M2C_StartSceneChange = 10014;
-		 public const ushort M2C_RemoveUnits = 10015;
-		 public const ushort C2M_PathfindingResult = 10016;
-		 public const ushort C2M_Stop = 10017;
-		 public const ushort M2C_PathfindingResult = 10018;
-		 public const ushort M2C_Stop = 10019;
-		 public const ushort C2G_Ping = 10020;
-		 public const ushort G2C_Ping = 10021;
-		 public const ushort G2C_Test = 10022;
-		 public const ushort C2M_Reload = 10023;
-		 public const ushort M2C_Reload = 10024;
-		 public const ushort C2R_Login = 10025;
-		 public const ushort R2C_Login = 10026;
-		 public const ushort C2G_LoginGate = 10027;
-		 public const ushort G2C_LoginGate = 10028;
-		 public const ushort G2C_TestHotfixMessage = 10029;
-		 public const ushort C2M_TestRobotCase = 10030;
-		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort IntKV = 10011;
+		 public const ushort UnitInfo = 10012;
+		 public const ushort M2C_CreateUnits = 10013;
+		 public const ushort M2C_CreateMyUnit = 10014;
+		 public const ushort M2C_StartSceneChange = 10015;
+		 public const ushort M2C_RemoveUnits = 10016;
+		 public const ushort C2M_PathfindingResult = 10017;
+		 public const ushort C2M_Stop = 10018;
+		 public const ushort M2C_PathfindingResult = 10019;
+		 public const ushort M2C_Stop = 10020;
+		 public const ushort C2G_Ping = 10021;
+		 public const ushort G2C_Ping = 10022;
+		 public const ushort G2C_Test = 10023;
+		 public const ushort C2M_Reload = 10024;
+		 public const ushort M2C_Reload = 10025;
+		 public const ushort C2R_Login = 10026;
+		 public const ushort R2C_Login = 10027;
+		 public const ushort C2G_LoginGate = 10028;
+		 public const ushort G2C_LoginGate = 10029;
+		 public const ushort G2C_TestHotfixMessage = 10030;
+		 public const ushort C2M_TestRobotCase = 10031;
+		 public const ushort M2C_TestRobotCase = 10032;
+		 public const ushort C2M_TransferMap = 10033;
+		 public const ushort M2C_TransferMap = 10034;
+		 public const ushort C2G_Benchmark = 10035;
+		 public const ushort G2C_Benchmark = 10036;
 	}
 }