forked from zxl/LaboratoryProtection
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
|
using Cysharp.Threading.Tasks;
|
|||
|
using Cysharp.Threading.Tasks.Triggers;
|
|||
|
|
|||
|
using PMaker.Await;
|
|||
|
using PMaker.HighlightPlus;
|
|||
|
|
|||
|
using System;
|
|||
|
using System.Threading;
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace PMaker
|
|||
|
{
|
|||
|
public static class AwaitHighlightGameObjectExtension
|
|||
|
{
|
|||
|
public static async UniTask WaitClickHighlightAsync(this GameObject go, CancellationToken cancellationToken = default)
|
|||
|
{
|
|||
|
|
|||
|
go.OnHightlight();
|
|||
|
var isCanceled = await go.WaitClick(cancellationToken).SuppressCancellationThrow();
|
|||
|
go.OffHightlight();
|
|||
|
|
|||
|
if (isCanceled)
|
|||
|
{
|
|||
|
throw new OperationCanceledException();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static async UniTask WaitClickHighlightAsync(this GameObject go, CancellationToken cancellationToken = default, params string[] childsName)
|
|||
|
{
|
|||
|
var root = go.transform;
|
|||
|
foreach (var item in childsName)
|
|||
|
{
|
|||
|
root = root.transform.Find(item);
|
|||
|
}
|
|||
|
go = root.gameObject;
|
|||
|
go.OnHightlight();
|
|||
|
var isCanceled = await go.WaitClick(cancellationToken).SuppressCancellationThrow();
|
|||
|
go.OffHightlight();
|
|||
|
|
|||
|
if (isCanceled)
|
|||
|
{
|
|||
|
throw new OperationCanceledException();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|