// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using UltimateXR.Extensions.System.Threading; using UnityEngine.UI; namespace UltimateXR.Extensions.Unity.UI { /// /// extensions. /// public static class ButtonExt { #region Public Methods /// /// Asynchronously waits until a is clicked. /// /// Button to wait for /// Optional cancellation token, to cancel the task /// Awaitable task that will finish once the button was clicked or the was canceled public static async Task WaitForClickAsync(this Button self, CancellationToken ct = default) { bool isClicked = false; void ButtonClicked() { isClicked = true; } self.onClick.AddListener(ButtonClicked); await TaskExt.WaitUntil(() => isClicked, ct); self.onClick.RemoveListener(ButtonClicked); } /// /// Asynchronously waits until a is clicked. Returns the that was clicked. /// /// Button to wait for /// Optional cancellation token, to cancel the task /// /// Awaitable task that will finish once the button was clicked or the was canceled, and that /// returns the that was clicked /// public static async Task