From c9e5a9b2e636462a7122cc5e0146d26f31327c83 Mon Sep 17 00:00:00 2001 From: tanghai Date: Sat, 24 Mar 2018 12:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A5=E5=90=8E=E5=86=8D=E4=B9=9F=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=89=8B=E5=8A=A8=E6=B7=BB=E5=8A=A0BsonKnowT?= =?UTF-8?q?ype=E6=A0=87=E7=AD=BE=E5=95=A6=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/App/Program.cs | 3 +-- Server/Model/Base/Helper/MongoHelper.cs | 16 +++++++++++++++- Server/Model/Base/Object/ComponentAttribute.cs | 12 ------------ .../Base/Object/ComponentWithIdAttribute.cs | 9 --------- Server/Model/Base/Object/EntityAttribute.cs | 11 ----------- Unity/Assets/Editor/Helper/MongoHelper.cs | 16 +++++++++++++++- .../Scripts/Base/Object/ComponentAttribute.cs | 10 ---------- .../Base/Object/ComponentAttribute.cs.meta | 12 ------------ .../Base/Object/ComponentWithIdAttribute.cs | 9 --------- .../Base/Object/ComponentWithIdAttribute.cs.meta | 12 ------------ .../Scripts/Base/Object/EntityAttribute.cs | 8 -------- .../Scripts/Base/Object/EntityAttribute.cs.meta | 12 ------------ .../Scripts/Module/Config/AConfigComponent.cs | 10 +--------- Unity/Unity.csproj | 14 +++++++------- 14 files changed, 39 insertions(+), 115 deletions(-) delete mode 100644 Server/Model/Base/Object/ComponentAttribute.cs delete mode 100644 Server/Model/Base/Object/ComponentWithIdAttribute.cs delete mode 100644 Server/Model/Base/Object/EntityAttribute.cs delete mode 100644 Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs delete mode 100644 Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs.meta delete mode 100644 Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs delete mode 100644 Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs.meta delete mode 100644 Unity/Assets/Scripts/Base/Object/EntityAttribute.cs delete mode 100644 Unity/Assets/Scripts/Base/Object/EntityAttribute.cs.meta diff --git a/Server/App/Program.cs b/Server/App/Program.cs index e9e474bf..0161144a 100644 --- a/Server/App/Program.cs +++ b/Server/App/Program.cs @@ -2,6 +2,7 @@ using System.Net; using System.Threading; using ETModel; +using MongoDB.Bson.Serialization; using NLog; namespace App @@ -13,8 +14,6 @@ namespace App // 异步方法全部会回掉到主线程 OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(contex); - - MongoHelper.Init(); try { diff --git a/Server/Model/Base/Helper/MongoHelper.cs b/Server/Model/Base/Helper/MongoHelper.cs index f13fdc02..5e04d012 100644 --- a/Server/Model/Base/Helper/MongoHelper.cs +++ b/Server/Model/Base/Helper/MongoHelper.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Reflection; using MongoDB.Bson; using MongoDB.Bson.IO; using MongoDB.Bson.Serialization; @@ -9,8 +10,21 @@ namespace ETModel { public static class MongoHelper { - public static void Init() + static MongoHelper() { + Type bsonClassMap = typeof(BsonClassMap); + MethodInfo methodInfo = bsonClassMap.GetMethod("RegisterClassMap", new Type[] { }); + + Type[] types = typeof(Game).Assembly.GetTypes(); + foreach (Type type in types) + { + if (!type.IsSubclassOf(typeof(Component))) + { + continue; + } + methodInfo.MakeGenericMethod(type).Invoke(null, null); + } + BsonSerializer.RegisterSerializer(new EnumSerializer(BsonType.String)); } diff --git a/Server/Model/Base/Object/ComponentAttribute.cs b/Server/Model/Base/Object/ComponentAttribute.cs deleted file mode 100644 index 1ea51c06..00000000 --- a/Server/Model/Base/Object/ComponentAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel -{ - [BsonKnownTypes(typeof(AConfigComponent))] - [BsonKnownTypes(typeof(UnitGateComponent))] - [BsonKnownTypes(typeof(NumericComponent))] - [BsonKnownTypes(typeof(ComponentWithId))] - public partial class Component - { - } -} \ No newline at end of file diff --git a/Server/Model/Base/Object/ComponentWithIdAttribute.cs b/Server/Model/Base/Object/ComponentWithIdAttribute.cs deleted file mode 100644 index 261698fe..00000000 --- a/Server/Model/Base/Object/ComponentWithIdAttribute.cs +++ /dev/null @@ -1,9 +0,0 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel -{ - [BsonKnownTypes(typeof(Entity))] - public partial class ComponentWithId - { - } -} \ No newline at end of file diff --git a/Server/Model/Base/Object/EntityAttribute.cs b/Server/Model/Base/Object/EntityAttribute.cs deleted file mode 100644 index 0864424c..00000000 --- a/Server/Model/Base/Object/EntityAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel -{ - [BsonKnownTypes(typeof(Location))] - [BsonKnownTypes(typeof(Recharge))] - [BsonKnownTypes(typeof(RechargeRecord))] - public partial class Entity - { - } -} diff --git a/Unity/Assets/Editor/Helper/MongoHelper.cs b/Unity/Assets/Editor/Helper/MongoHelper.cs index aff9a60d..3aff4b49 100644 --- a/Unity/Assets/Editor/Helper/MongoHelper.cs +++ b/Unity/Assets/Editor/Helper/MongoHelper.cs @@ -5,13 +5,27 @@ using MongoDB.Bson.IO; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Serializers; using System.Collections.Generic; +using System.Reflection; namespace ETModel { public static class MongoHelper { - public static void Init() + static MongoHelper() { + Type bsonClassMap = typeof(BsonClassMap); + MethodInfo methodInfo = bsonClassMap.GetMethod("RegisterClassMap", new Type[] { }); + + Type[] types = typeof(Game).Assembly.GetTypes(); + foreach (Type type in types) + { + if (!type.IsSubclassOf(typeof(Component))) + { + continue; + } + methodInfo.MakeGenericMethod(type).Invoke(null, null); + } + BsonSerializer.RegisterSerializer(new EnumSerializer(BsonType.String)); } diff --git a/Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs b/Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs deleted file mode 100644 index c17b1176..00000000 --- a/Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel -{ - [BsonKnownTypes(typeof(AConfigComponent))] - [BsonKnownTypes(typeof(ComponentWithId))] - public partial class Component - { - } -} \ No newline at end of file diff --git a/Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs.meta b/Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs.meta deleted file mode 100644 index 75ee4a54..00000000 --- a/Unity/Assets/Scripts/Base/Object/ComponentAttribute.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 7f862da8d48947748af29b67dcda2dd2 -timeCreated: 1512358818 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs b/Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs deleted file mode 100644 index 261698fe..00000000 --- a/Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs +++ /dev/null @@ -1,9 +0,0 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel -{ - [BsonKnownTypes(typeof(Entity))] - public partial class ComponentWithId - { - } -} \ No newline at end of file diff --git a/Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs.meta b/Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs.meta deleted file mode 100644 index 4fa83d57..00000000 --- a/Unity/Assets/Scripts/Base/Object/ComponentWithIdAttribute.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 580a3c3b48fdd5b438d5e185e407db41 -timeCreated: 1521513816 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Unity/Assets/Scripts/Base/Object/EntityAttribute.cs b/Unity/Assets/Scripts/Base/Object/EntityAttribute.cs deleted file mode 100644 index c4ed7edc..00000000 --- a/Unity/Assets/Scripts/Base/Object/EntityAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel -{ - public partial class Entity - { - } -} diff --git a/Unity/Assets/Scripts/Base/Object/EntityAttribute.cs.meta b/Unity/Assets/Scripts/Base/Object/EntityAttribute.cs.meta deleted file mode 100644 index 8729edb4..00000000 --- a/Unity/Assets/Scripts/Base/Object/EntityAttribute.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: cc5bfaad42962324d8fa891fea5efba7 -timeCreated: 1512358818 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Unity/Assets/Scripts/Module/Config/AConfigComponent.cs b/Unity/Assets/Scripts/Module/Config/AConfigComponent.cs index 065ac1df..dec50bb5 100644 --- a/Unity/Assets/Scripts/Module/Config/AConfigComponent.cs +++ b/Unity/Assets/Scripts/Module/Config/AConfigComponent.cs @@ -1,16 +1,8 @@ -using MongoDB.Bson.Serialization.Attributes; - -namespace ETModel +namespace ETModel { /// /// 每个Config的基类 /// - [BsonKnownTypes(typeof(ClientConfig))] - [BsonKnownTypes(typeof(InnerConfig))] - [BsonKnownTypes(typeof(OuterConfig))] - [BsonKnownTypes(typeof(HttpConfig))] - [BsonKnownTypes(typeof(DBConfig))] - [BsonKnownTypes(typeof(RunServerConfig))] public abstract class AConfigComponent: Component, ISerializeToEntity { } diff --git a/Unity/Unity.csproj b/Unity/Unity.csproj index fa8f0d0a..091df97b 100644 --- a/Unity/Unity.csproj +++ b/Unity/Unity.csproj @@ -12,12 +12,15 @@ {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} .NETFramework v4.6 - - + + + + Game:1 Android:13 2017.1.3p2 - + + 6 @@ -146,12 +149,9 @@ - - - @@ -774,4 +774,4 @@ - + \ No newline at end of file -- GitLab