using System; using XGame.Framework.Quality; using XGame.Framework.Time; namespace XGame.Framework.UI { /// /// 每个UIView一个UIContext实例 /// public class UIContext : IDisposable { public IQualityModule Quality { get; private set; } public ITimeModule Time { get; private set; } public IUIModule UI { get; private set; } /// /// 资源加载模块,需要时才创建 /// private IUIAssetModule _asset; /// /// 资源加载模块 /// public IUIAssetModule Asset => _asset ?? (_asset = new UIAssetModule()); public UIContext(IQualityModule qualityModule, ITimeModule timeModule, IUIModule uiModule) { Quality = qualityModule; Time = timeModule; UI = uiModule; } public UIContext Clone() { return new UIContext(Quality, Time, UI); } /// /// 停止所有的加载事件 /// public void StopAllAsyncs() { _asset?.StopAllAsyncs(); } void IDisposable.Dispose() { Quality = null; Time = null; UI = null; (_asset as IDisposable)?.Dispose(); _asset = null; } } public interface IUIContextSetter { UIContext Context { set; } } }