1
This commit is contained in:
@@ -12,19 +12,18 @@ namespace BITKit.UX
|
||||
protected readonly CancellationTokenSource CancellationToken;
|
||||
protected readonly IUXService UXService;
|
||||
protected VisualElement RootVisualElement { get; set; }
|
||||
private bool _initialized;
|
||||
protected bool IsInitialized { get; private set; }
|
||||
protected UIToolkitOverlay(IUXService uxService, CancellationTokenSource cancellationToken)
|
||||
{
|
||||
UXService = uxService;
|
||||
CancellationToken = cancellationToken;
|
||||
CancellationToken.Token.Register(Dispose);
|
||||
}
|
||||
|
||||
protected abstract string DocumentPath { get; }
|
||||
// ReSharper disable once MemberCanBeProtected.Global
|
||||
public virtual async UniTask InitializeAsync()
|
||||
{
|
||||
if(_initialized)return;
|
||||
if(IsInitialized)return;
|
||||
var asset =await ModService.LoadAsset<VisualTreeAsset>(DocumentPath);
|
||||
var root= RootVisualElement = UXService.Root.As<VisualElement>().Create(asset);
|
||||
|
||||
@@ -40,12 +39,12 @@ namespace BITKit.UX
|
||||
root.style.right = 0;
|
||||
|
||||
UXUtils.Inject(this);
|
||||
_initialized = true;
|
||||
IsInitialized = true;
|
||||
}
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if(RootVisualElement is null)return;
|
||||
_initialized = false;
|
||||
IsInitialized = false;
|
||||
RootVisualElement.RemoveFromHierarchy();
|
||||
RootVisualElement = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user