1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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
- {
- /// <summary>
- /// 每个NodeGroup一个Context
- /// </summary>
- 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; }
- /// <summary>
- /// 资源加载模块,需要时才创建
- /// </summary>
- private IAssetModule _asset;
- /// <summary>
- /// 资源加载模块,需要时才创建
- /// </summary>
- public IAssetModule Asset => _asset ?? (_asset = new AssetModule());
- /// <summary>
- /// NodeTree
- /// </summary>
- 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;
- }
- }
- }
|