NodeContext.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using XGame.Framework.Asset;
  3. using XGame.Framework.Map;
  4. using XGame.Framework.Quality;
  5. using XGame.Framework.Time;
  6. using XGame.Framework.UI;
  7. namespace XGame.Framework.Nodes
  8. {
  9. /// <summary>
  10. /// 每个NodeGroup一个Context
  11. /// </summary>
  12. public sealed class NodeContext : IDisposable, INodeTreeSetter
  13. {
  14. public IQualityModule Quality { get; private set; }
  15. public ITimeModule Time { get; private set; }
  16. public IUIModule UI { get; private set; }
  17. public IMapModule Map { get; private set; }
  18. /// <summary>
  19. /// 资源加载模块,需要时才创建
  20. /// </summary>
  21. private IAssetModule _asset;
  22. /// <summary>
  23. /// 资源加载模块,需要时才创建
  24. /// </summary>
  25. public IAssetModule Asset => _asset ?? (_asset = new AssetModule());
  26. /// <summary>
  27. /// NodeTree
  28. /// </summary>
  29. public INodeTree Tree { get; private set; }
  30. INodeTree INodeTreeSetter.NodeTree { set => Tree = value; }
  31. public NodeContext(IQualityModule qualityModule, ITimeModule timeModule, IUIModule uiModule, IMapModule mapModule)
  32. {
  33. Quality = qualityModule;
  34. Time = timeModule;
  35. UI = uiModule;
  36. Map = mapModule;
  37. }
  38. public NodeContext Clone()
  39. {
  40. var context = new NodeContext(Quality, Time, UI, Map);
  41. (context as INodeTreeSetter).NodeTree = Tree;
  42. return context;
  43. }
  44. void IDisposable.Dispose()
  45. {
  46. Quality = null;
  47. UI = null;
  48. Time = null;
  49. (_asset as IDisposable)?.Dispose();
  50. _asset = null;
  51. }
  52. }
  53. }