Add ultimate xr
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="ButtonExt.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="Button" /> extensions.
|
||||
/// </summary>
|
||||
public static class ButtonExt
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously waits until a <see cref="Button" /> is clicked.
|
||||
/// </summary>
|
||||
/// <param name="self">Button to wait for</param>
|
||||
/// <param name="ct">Optional cancellation token, to cancel the task</param>
|
||||
/// <returns>Awaitable task that will finish once the button was clicked or the <see cref="Task" /> was canceled</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously waits until a <see cref="Button" /> is clicked. Returns the <see cref="Button" /> that was clicked.
|
||||
/// </summary>
|
||||
/// <param name="self">Button to wait for</param>
|
||||
/// <param name="ct">Optional cancellation token, to cancel the task</param>
|
||||
/// <returns>
|
||||
/// Awaitable task that will finish once the button was clicked or the <see cref="Task" /> was canceled, and that
|
||||
/// returns the <see cref="Button" /> that was clicked
|
||||
/// </returns>
|
||||
public static async Task<Button> ReadAsync(this Button self, CancellationToken ct)
|
||||
{
|
||||
await self.WaitForClickAsync(ct);
|
||||
return ct.IsCancellationRequested ? null : self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously waits until a <see cref="Button" /> in a set is clicked. Returns the <see cref="Button" /> that was
|
||||
/// clicked.
|
||||
/// </summary>
|
||||
/// <param name="ct">Cancellation token, to cancel the task</param>
|
||||
/// <param name="buttons">Buttons to wait for</param>
|
||||
/// <returns>
|
||||
/// Awaitable task that will finish once a button was clicked or the <see cref="Task" /> was canceled, and that
|
||||
/// returns the <see cref="Button" /> that was clicked
|
||||
/// </returns>
|
||||
public static Task<Button> ReadAsync(CancellationToken ct, params Button[] buttons)
|
||||
{
|
||||
return buttons.ReadAsync(ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously waits until a <see cref="Button" /> in a set is clicked. Returns the <see cref="Button" /> that was
|
||||
/// clicked.
|
||||
/// </summary>
|
||||
/// <param name="buttons">Buttons to wait for</param>
|
||||
/// <param name="ct">Optional cancellation token, to cancel the task</param>
|
||||
/// <returns>
|
||||
/// Awaitable task that will finish once a button was clicked or the <see cref="Task" /> was canceled, and that
|
||||
/// returns the <see cref="Button" /> that was clicked
|
||||
/// </returns>
|
||||
public static async Task<Button> ReadAsync(this Button[] buttons, CancellationToken ct)
|
||||
{
|
||||
using CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
IEnumerable<Task<Button>> tasks = buttons.Select(b => b.ReadAsync(ct));
|
||||
Task<Button> finishedTask = await Task.WhenAny(tasks);
|
||||
|
||||
if (!finishedTask.IsCanceled)
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
|
||||
return await finishedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2efa665a655f39e449606ff3b59ddd72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="GraphicExt.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UltimateXR.Extensions.Unity.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="Graphic" /> extensions.
|
||||
/// </summary>
|
||||
public static class GraphicExt
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Sets the alpha value of a <see cref="Graphic" /> component.
|
||||
/// </summary>
|
||||
/// <param name="graphic">Target <see cref="Graphic" /> component to set the alpha value of</param>
|
||||
/// <param name="alpha">New alpha value</param>
|
||||
public static void SetAlpha(this Graphic graphic, float alpha)
|
||||
{
|
||||
Color color = graphic.color;
|
||||
color.a = alpha;
|
||||
graphic.color = color;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a71caaa359fa314aa013afc0e41da86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user