Game.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text;
  4. namespace Model
  5. {
  6. public static class Game
  7. {
  8. private static HashSet<Disposer> disposers;
  9. private static EntityEventManager entityEventManager;
  10. private static Scene scene;
  11. public static Scene Scene
  12. {
  13. get
  14. {
  15. if (scene == null)
  16. {
  17. scene = new Scene();
  18. scene.AddComponent<EventComponent>();
  19. }
  20. return scene;
  21. }
  22. }
  23. public static HashSet<Disposer> Disposers
  24. {
  25. get
  26. {
  27. if (disposers == null)
  28. {
  29. disposers = new HashSet<Disposer>();
  30. }
  31. return disposers;
  32. }
  33. }
  34. public static void CloseScene()
  35. {
  36. scene.Dispose();
  37. scene = null;
  38. }
  39. public static void ClearDisposers()
  40. {
  41. foreach (Disposer disposer in Disposers)
  42. {
  43. disposer.Dispose();
  44. }
  45. disposers.Clear();
  46. disposers = null;
  47. }
  48. public static EntityEventManager EntityEventManager
  49. {
  50. get
  51. {
  52. if (entityEventManager == null)
  53. {
  54. entityEventManager = new EntityEventManager();
  55. }
  56. return entityEventManager;
  57. }
  58. set
  59. {
  60. entityEventManager = value;
  61. }
  62. }
  63. public static string DisposerInfo()
  64. {
  65. var info = new Dictionary<string, int>();
  66. foreach (Disposer disposer in Disposers)
  67. {
  68. if (info.ContainsKey(disposer.GetType().Name))
  69. {
  70. info[disposer.GetType().Name] += 1;
  71. }
  72. else
  73. {
  74. info[disposer.GetType().Name] = 1;
  75. }
  76. }
  77. info = info.OrderByDescending(s => s.Value).ToDictionary(p => p.Key, p => p.Value);
  78. StringBuilder sb = new StringBuilder();
  79. sb.Append("\r\n");
  80. foreach (string key in info.Keys)
  81. {
  82. sb.Append($"{info[key],10} {key}\r\n");
  83. }
  84. return sb.ToString();
  85. }
  86. }
  87. }