Share.cs 761 B

123456789101112131415161718192021222324252627282930313233343536
  1. using Base;
  2. namespace Model
  3. {
  4. /// <summary>
  5. /// 游戏和扩展编辑器都需要用到的数据放在这个Scene上面
  6. /// </summary>
  7. public sealed class Share
  8. {
  9. private static Entity share;
  10. public static Entity Scene
  11. {
  12. get
  13. {
  14. if (share == null)
  15. {
  16. share = new Entity();
  17. share.AddComponent<Scene>();
  18. share.AddComponent<EventComponent>();
  19. share.AddComponent<LogComponent>();
  20. GlobalConfigComponent globalConfigComponent = share.AddComponent<GlobalConfigComponent>();
  21. share.AddComponent<NetworkComponent, NetworkProtocol>(globalConfigComponent.GlobalProto.Protocol);
  22. }
  23. return share;
  24. }
  25. }
  26. public static void Close()
  27. {
  28. Entity scene = share;
  29. share = null;
  30. scene?.Dispose();
  31. }
  32. }
  33. }