Jelajahi Sumber

MongoHelper.RegisterStruct增加防重判断,防止注册struct报错

tanghai 2 tahun lalu
induk
melakukan
656ffbf575

+ 4 - 1
Unity/Assets/Scripts/Core/Serialize/MongoHelper.cs

@@ -119,7 +119,10 @@ namespace ET
 
         public static void RegisterStruct<T>() where T : struct
         {
-            BsonSerializer.RegisterSerializer(typeof (T), new StructBsonSerialize<T>());
+            if (BsonSerializer.LookupSerializer(typeof (T)) == null)
+            {
+                BsonSerializer.RegisterSerializer(typeof (T), new StructBsonSerialize<T>());
+            }
         }
 
         public static string ToJson(object obj)

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Entry.cs

@@ -34,8 +34,8 @@ namespace ET
         {
             WinPeriod.Init();
             
-            MongoHelper.RegisterStruct<LSInput>();
             MongoHelper.Register();
+            MongoHelper.RegisterStruct<LSInput>();
             
             Game.AddSingleton<EntitySystemSingleton>();
             Game.AddSingleton<LSEntitySystemSington>();