UIContext.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using XGame.Framework.Quality;
  3. using XGame.Framework.Time;
  4. namespace XGame.Framework.UI
  5. {
  6. /// <summary>
  7. /// 每个UIView一个UIContext实例
  8. /// </summary>
  9. public class UIContext : IDisposable
  10. {
  11. public IQualityModule Quality { get; private set; }
  12. public ITimeModule Time { get; private set; }
  13. public IUIModule UI { get; private set; }
  14. /// <summary>
  15. /// 资源加载模块,需要时才创建
  16. /// </summary>
  17. private IUIAssetModule _asset;
  18. /// <summary>
  19. /// 资源加载模块
  20. /// </summary>
  21. public IUIAssetModule Asset => _asset ?? (_asset = new UIAssetModule());
  22. public UIContext(IQualityModule qualityModule, ITimeModule timeModule, IUIModule uiModule)
  23. {
  24. Quality = qualityModule;
  25. Time = timeModule;
  26. UI = uiModule;
  27. }
  28. public UIContext Clone()
  29. {
  30. return new UIContext(Quality, Time, UI);
  31. }
  32. /// <summary>
  33. /// 停止所有的加载事件
  34. /// </summary>
  35. public void StopAllAsyncs()
  36. {
  37. _asset?.StopAllAsyncs();
  38. }
  39. void IDisposable.Dispose()
  40. {
  41. Quality = null;
  42. Time = null;
  43. UI = null;
  44. (_asset as IDisposable)?.Dispose();
  45. _asset = null;
  46. }
  47. }
  48. public interface IUIContextSetter
  49. {
  50. UIContext Context { set; }
  51. }
  52. }