提交 b0947ae3 编写于 作者: T tanghai

NumericComponent完美的序列化反序列化

上级 9087ece9
{ "_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" : "*" }
......@@ -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>();
......
......@@ -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)
{
......

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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册