MapContext.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using XGame.Framework.Quality;
  3. using XGame.Framework.Time;
  4. namespace XGame.Framework.Map
  5. {
  6. public class MapContext : IDisposable
  7. {
  8. public IQualityModule Quality { get; private set; }
  9. public ITimeModule Time { get; private set; }
  10. public IMapModule Map { get; private set; }
  11. /// <summary>
  12. /// 资源加载模块,需要时才创建
  13. /// </summary>
  14. private IMapAssetModule _assetModule;
  15. public IMapAssetModule Asset => _assetModule ?? (_assetModule = new MapAssetModule(this));
  16. public MapContext(IQualityModule quality, ITimeModule time, IMapModule map)
  17. {
  18. Quality = quality;
  19. Time = time;
  20. Map = map;
  21. }
  22. public MapContext Clone()
  23. {
  24. return new MapContext(Quality, Time, Map);
  25. }
  26. void IDisposable.Dispose()
  27. {
  28. Quality = null;
  29. Time = null;
  30. Map = null;
  31. (_assetModule as IDisposable)?.Dispose();
  32. _assetModule = null;
  33. }
  34. }
  35. public interface IMapContextSetter
  36. {
  37. MapContext Context { set; }
  38. }
  39. }