MongoRegister.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using MongoDB.Bson.Serialization;
  4. using MongoDB.Bson.Serialization.Conventions;
  5. using TrueSync;
  6. using Unity.Mathematics;
  7. namespace ET
  8. {
  9. public static class MongoRegister
  10. {
  11. private static void RegisterStruct<T>() where T : struct
  12. {
  13. BsonSerializer.RegisterSerializer(typeof (T), new StructBsonSerialize<T>());
  14. }
  15. public static void Register()
  16. {
  17. // 自动注册IgnoreExtraElements
  18. ConventionPack conventionPack = new() { new IgnoreExtraElementsConvention(true) };
  19. ConventionRegistry.Register("IgnoreExtraElements", conventionPack, type => true);
  20. RegisterStruct<float2>();
  21. RegisterStruct<float3>();
  22. RegisterStruct<float4>();
  23. RegisterStruct<quaternion>();
  24. RegisterStruct<FP>();
  25. RegisterStruct<TSVector>();
  26. RegisterStruct<TSVector2>();
  27. RegisterStruct<TSVector4>();
  28. RegisterStruct<TSQuaternion>();
  29. RegisterStruct<LSInput>();
  30. Dictionary<string, Type> types = CodeTypes.Instance.GetTypes();
  31. foreach (Type type in types.Values)
  32. {
  33. if (!type.IsSubclassOf(typeof (Object)))
  34. {
  35. continue;
  36. }
  37. if (type.IsGenericType)
  38. {
  39. continue;
  40. }
  41. BsonClassMap.LookupClassMap(type);
  42. }
  43. }
  44. }
  45. }