using System; using XGame.Framework.Asset; using XGame.Framework.Map; using XGame.Framework.Quality; using XGame.Framework.Time; using XGame.Framework.UI; namespace XGame.Framework.Nodes { /// /// 每个NodeGroup一个Context /// public sealed class NodeContext : IDisposable, INodeTreeSetter { public IQualityModule Quality { get; private set; } public ITimeModule Time { get; private set; } public IUIModule UI { get; private set; } public IMapModule Map { get; private set; } /// /// 资源加载模块,需要时才创建 /// private IAssetModule _asset; /// /// 资源加载模块,需要时才创建 /// public IAssetModule Asset => _asset ?? (_asset = new AssetModule()); /// /// NodeTree /// public INodeTree Tree { get; private set; } INodeTree INodeTreeSetter.NodeTree { set => Tree = value; } public NodeContext(IQualityModule qualityModule, ITimeModule timeModule, IUIModule uiModule, IMapModule mapModule) { Quality = qualityModule; Time = timeModule; UI = uiModule; Map = mapModule; } public NodeContext Clone() { var context = new NodeContext(Quality, Time, UI, Map); (context as INodeTreeSetter).NodeTree = Tree; return context; } void IDisposable.Dispose() { Quality = null; UI = null; Time = null; (_asset as IDisposable)?.Dispose(); _asset = null; } } }