1
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem.Composites;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
@@ -93,9 +94,15 @@ namespace BITKit.UX
|
||||
});
|
||||
}
|
||||
}
|
||||
public class UXAlert : MonoBehaviourSingleton<UXAlert>
|
||||
public class UXAlert : UIToolkitOverlay,IUXDialogue
|
||||
{
|
||||
[SerializeField] private UIDocument document;
|
||||
public static UXAlert Singleton;
|
||||
public UXAlert(IUXService uxService, CancellationTokenSource cancellationToken) : base(uxService, cancellationToken)
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
protected override string DocumentPath => "ux_global_alert";
|
||||
|
||||
[UXBindPath("title-label")]
|
||||
private Label _titleLabel;
|
||||
@@ -105,24 +112,19 @@ namespace BITKit.UX
|
||||
private Button _confirmButton;
|
||||
[UXBindPath("cancel-button")]
|
||||
private Button _cancelButton;
|
||||
private void Start()
|
||||
public override async UniTask InitializeAsync()
|
||||
{
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
|
||||
await base.InitializeAsync();
|
||||
UXUtils.Inject(this);
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Dispose()
|
||||
internal async void PrintAlertMessage(AlertMessage message)
|
||||
{
|
||||
}
|
||||
|
||||
internal void PrintAlertMessage(AlertMessage message)
|
||||
{
|
||||
if(destroyCancellationToken.IsCancellationRequested)return;
|
||||
if(CancellationToken.IsCancellationRequested)return;
|
||||
|
||||
BITAppForUnity.AllowCursor.AddElement(this);
|
||||
|
||||
await InitializeAsync();
|
||||
|
||||
document.rootVisualElement.SetActive(true);
|
||||
_titleLabel.text = message.title;
|
||||
_contextLabel.text = message.message;
|
||||
|
||||
@@ -150,12 +152,22 @@ namespace BITKit.UX
|
||||
_confirmButton.SetActive(true);
|
||||
_cancelButton.SetActive(false);
|
||||
}
|
||||
BITAppForUnity.AllowCursor.AddElement(this);
|
||||
|
||||
}
|
||||
private void Close()
|
||||
{
|
||||
document.rootVisualElement.SetActive(false);
|
||||
Dispose();
|
||||
BITAppForUnity.AllowCursor.RemoveElement(this);
|
||||
}
|
||||
public void Show(string content, string title = "Alert", Action confirmAction = null, Action<bool> onChoose = null)
|
||||
{
|
||||
PrintAlertMessage(new AlertMessage()
|
||||
{
|
||||
title = title,
|
||||
message = content,
|
||||
OnConfirm = confirmAction,
|
||||
OnChoice = onChoose
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user