1
This commit is contained in:
@@ -5,6 +5,7 @@ using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.InputSystem;
|
||||
using BITKit.Mod;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit.UX.Internal
|
||||
@@ -111,7 +112,7 @@ namespace BITKit.UX
|
||||
private readonly IUXService _uxService;
|
||||
private VisualElement _root;
|
||||
private VisualElement _container;
|
||||
private bool _isInitialized = false;
|
||||
private readonly UniTaskCompletionSource _waitUntilInitialized = new();
|
||||
public UXContextMenu(IUXService uxService)
|
||||
{
|
||||
_uxService = uxService;
|
||||
@@ -144,11 +145,14 @@ namespace BITKit.UX
|
||||
{
|
||||
Close();
|
||||
});
|
||||
_isInitialized = true;
|
||||
|
||||
_waitUntilInitialized.TrySetResult();
|
||||
|
||||
Close();
|
||||
}
|
||||
public void Create(ContextMenuBuilder builder)
|
||||
public async void Create(ContextMenuBuilder builder)
|
||||
{
|
||||
await _waitUntilInitialized.Task;
|
||||
var pos = Mouse.current.position.ReadValue();
|
||||
pos.y = Screen.height - pos.y;
|
||||
pos = RuntimePanelUtils.ScreenToPanel(_root.panel, pos);
|
||||
@@ -166,9 +170,9 @@ namespace BITKit.UX
|
||||
}
|
||||
builder.OnExecuted += Close;
|
||||
}
|
||||
private void Close()
|
||||
private async void Close()
|
||||
{
|
||||
if(_isInitialized is false)return;
|
||||
await _waitUntilInitialized.Task;
|
||||
_container.Clear();
|
||||
_root.SetActive(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user