Parcourir la source

NumericComponent完美的序列化反序列化

tanghai il y a 8 ans
Parent
commit
b0947ae3c9

+ 2 - 0
Config/StartConfig/Benchmark2.txt

@@ -0,0 +1,2 @@
+{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "components" : [{ "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }, { "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "HttpConfig", "Url" : "", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("98892711264291"), "components" : [{ "_t" : "ClientConfig", "Host" : "127.0.0.1", "Port" : 10002 }], "AppId" : 2, "AppType" : "Benchmark", "ServerIP" : "*" }

+ 0 - 8
Server/App/Program.cs

@@ -41,14 +41,6 @@ namespace App
 				Game.Scene.AddComponent<OpcodeTypeComponent>();
 				Game.Scene.AddComponent<MessageDispatherComponent>();
 
-				Unit unit = new Unit();
-				NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
-				numericComponent.Set(NumericType.Speed, 100);
-
-				Log.Debug(MongoHelper.ToJson(unit));
-				Unit unit2 = MongoHelper.FromJson<Unit>(MongoHelper.ToJson(unit));
-				Log.Debug(MongoHelper.ToJson(unit2));
-
 				// 根据不同的AppType添加不同的组件
 				OuterConfig outerConfig = startConfig.GetComponent<OuterConfig>();
 				InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();

+ 15 - 1
Server/Model/Component/NumericComponent.cs

@@ -4,10 +4,24 @@ using MongoDB.Bson.Serialization.Options;
 
 namespace Model
 {
+	[ObjectEvent]
+	public class NumericComponentEvent : ObjectEvent<NumericComponent>, IAwake
+	{
+		public void Awake()
+		{
+			this.Get().Awake();
+		}
+	}
+
 	public class NumericComponent : ComponentDB
 	{
 		[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
-		public readonly Dictionary<NumericType, int> NumericDic = new Dictionary<NumericType, int>();
+		public Dictionary<NumericType, int> NumericDic;
+
+		public void Awake()
+		{
+			this.NumericDic = new Dictionary<NumericType, int>();
+		}
 
 		public float GetAsFloat(NumericType numericType)
 		{

+ 1 - 1
Server/Server.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
-VisualStudioVersion = 15.0.26730.15
+VisualStudioVersion = 15.0.27004.2005
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.App", "App\Server.App.csproj", "{11464C2C-E0B6-476E-ABB1-87445E736B76}"
 EndProject