MongoRegister.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using MongoDB.Bson.Serialization;
  3. using MongoDB.Bson.Serialization.Conventions;
  4. using UnityEngine;
  5. namespace ET
  6. {
  7. public static class MongoRegister
  8. {
  9. static MongoRegister()
  10. {
  11. // 自动注册IgnoreExtraElements
  12. ConventionPack conventionPack = new ConventionPack { new IgnoreExtraElementsConvention(true) };
  13. ConventionRegistry.Register("IgnoreExtraElements", conventionPack, type => true);
  14. #if SERVER
  15. BsonSerializer.RegisterSerializer(typeof(Vector3), new StructBsonSerialize<Vector3>());
  16. BsonSerializer.RegisterSerializer(typeof(Vector4), new StructBsonSerialize<Vector4>());
  17. BsonSerializer.RegisterSerializer(typeof(Quaternion), new StructBsonSerialize<Quaternion>());
  18. #elif ROBOT
  19. BsonSerializer.RegisterSerializer(typeof(Quaternion), new StructBsonSerialize<Quaternion>());
  20. BsonSerializer.RegisterSerializer(typeof(Vector3), new StructBsonSerialize<Vector3>());
  21. BsonSerializer.RegisterSerializer(typeof(Vector4), new StructBsonSerialize<Vector4>());
  22. #else
  23. BsonSerializer.RegisterSerializer(typeof (Vector4), new StructBsonSerialize<Vector4>());
  24. BsonSerializer.RegisterSerializer(typeof (Vector3), new StructBsonSerialize<Vector3>());
  25. #endif
  26. var types = Game.EventSystem.GetTypes();
  27. foreach (Type type in types)
  28. {
  29. if (!type.IsSubclassOf(typeof (Object)))
  30. {
  31. continue;
  32. }
  33. if (type.IsGenericType)
  34. {
  35. continue;
  36. }
  37. BsonClassMap.LookupClassMap(type);
  38. }
  39. }
  40. public static void Init()
  41. {
  42. }
  43. }
  44. }