123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using XGame.Framework.Quality;
- using XGame.Framework.Time;
- namespace XGame.Framework.UI
- {
-
-
-
- public sealed class UIContext : IContext, IUIViewAdapter, IDisposable
- {
- public IQualityModule Quality { get; private set; }
- private ITimeModule _timeModule;
- private ITimeProxy _timeProxy;
- public ITimeProxy Time => _timeProxy ?? (_timeProxy = new TimeProxy(_timeModule));
- public IUIModule UI { get; private set; }
-
-
-
- private IUIAssetModule _asset;
-
-
-
- public IUIAssetModule Asset => _asset ?? (_asset = (UI as IUIAssetModuleCreator).Create(this));
- public UIContext(IQualityModule qualityModule, ITimeModule timeModule, IUIModule uiModule)
- {
- Quality = qualityModule;
- _timeModule = timeModule;
- UI = uiModule;
- }
- public UIContext Clone()
- {
- return new UIContext(Quality, _timeModule, UI);
- }
-
-
-
-
- public void ClosePanel(bool isDestroy = false)
- {
- UI.Close(_uikey, isDestroy);
- }
-
-
-
- public void Clear()
- {
- _timeProxy?.CancelAll();
- _asset?.StopAllAsyncs();
- }
- void IDisposable.Dispose()
- {
- Quality = null;
- _timeModule = null;
- UI = null;
- _timeProxy?.CancelAll();
- _timeProxy = null;
- (_asset as IDisposable)?.Dispose();
- _asset = null;
-
- _uikey = null;
- }
-
-
-
-
- private UIKey _uikey;
- public UIKey Key => _uikey;
- UIKey IUIViewAdapter.Key { set => _uikey = value; }
-
-
- TNestedView IUIViewAdapter.CreateNested<TNestedView>(IUINested nested, bool isStatic)
- {
- var nestedView = Activator.CreateInstance<TNestedView>();
- (nestedView as INestedInternal).Init(this, nested, isStatic);
- return nestedView;
- }
- INestedView IUIViewAdapter.CreateNested(Type nestedViewType, IUINested nested, bool isStatic)
- {
- var nestedView = Activator.CreateInstance(nestedViewType) as INestedInternal;
- if (nestedView == null)
- {
- Log.Error($"CreateNested 类型错误. Type:{nestedViewType} isStatic:{isStatic}");
- }
- else
- {
- nestedView.Init(this, nested, isStatic);
- }
- return nestedView;
- }
- }
- public interface IUIContextSetter
- {
- UIContext Context { set; }
- }
- }
|