소스 검색

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

tanghai 2 년 전
부모
커밋
656ffbf575
2개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 1
      Unity/Assets/Scripts/Core/Serialize/MongoHelper.cs
  2. 1 1
      Unity/Assets/Scripts/Model/Share/Entry.cs

+ 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>();