DBManagerComponentSystem.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. namespace ET
  3. {
  4. public static class DBManagerComponentSystem
  5. {
  6. [ObjectSystem]
  7. public class DBManagerComponentAwakeSystem: AwakeSystem<DBManagerComponent>
  8. {
  9. public override void Awake(DBManagerComponent self)
  10. {
  11. DBManagerComponent.Instance = self;
  12. }
  13. }
  14. [ObjectSystem]
  15. public class DBManagerComponentDestroySystem: DestroySystem<DBManagerComponent>
  16. {
  17. public override void Destroy(DBManagerComponent self)
  18. {
  19. DBManagerComponent.Instance = null;
  20. }
  21. }
  22. public static DBComponent GetZoneDB(this DBManagerComponent self, int zone)
  23. {
  24. DBComponent dbComponent = self.DBComponents[zone];
  25. if (dbComponent != null)
  26. {
  27. return dbComponent;
  28. }
  29. StartZoneConfig startZoneConfig = StartZoneConfigCategory.Instance.Get(zone);
  30. if (startZoneConfig.DBConnection == "")
  31. {
  32. throw new Exception($"zone: {zone} not found mongo connect string");
  33. }
  34. dbComponent = self.AddChild<DBComponent, string, string, int>(startZoneConfig.DBConnection, startZoneConfig.DBName, zone);
  35. self.DBComponents[zone] = dbComponent;
  36. return dbComponent;
  37. }
  38. }
  39. }