forked from zxl/LaboratoryProtection
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
|
using Cysharp.Threading.Tasks;
|
|||
|
|
|||
|
using MessagePipe;
|
|||
|
|
|||
|
using PMaker.Await;
|
|||
|
using PMaker.MessagePipe;
|
|||
|
|
|||
|
using System.Threading;
|
|||
|
|
|||
|
using UniRx;
|
|||
|
using UniRx.Triggers;
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class UIMoudleSelect : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField]
|
|||
|
private Button[] _btns;
|
|||
|
|
|||
|
private void Reset()
|
|||
|
{
|
|||
|
this._btns = this.GetComponentsInChildren<Button>(true);
|
|||
|
}
|
|||
|
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
MessageKit.GetAsyncSubscriber<string, int>()
|
|||
|
.Subscribe(this.name, async (_, token) => {
|
|||
|
await _btns[_].OnClickAsync(token);
|
|||
|
})
|
|||
|
.AddTo(this);
|
|||
|
|
|||
|
MessageKit.GetFuncAsyncSubscriber<string, int>()
|
|||
|
.Subscribe(this.name + "Any", async (_, token) => {
|
|||
|
var (IsCanceled, Result) = await UniTask.WhenAny(this._btns.Select(btn => btn.OnClickAsync(token))).SuppressCancellationThrow();
|
|||
|
if (IsCanceled != true)
|
|||
|
{
|
|||
|
_.value = Result;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_.value = -1;
|
|||
|
}
|
|||
|
})
|
|||
|
.AddTo(this);
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
MessageKit.Publish("全局", ("类型Btn", false));
|
|||
|
this.OnEnableAsObservable()
|
|||
|
.Subscribe(_ => {
|
|||
|
MessageKit.Publish("全局", ("类型Btn", false));
|
|||
|
})
|
|||
|
.AddTo(this);
|
|||
|
|
|||
|
this.OnDisableAsObservable()
|
|||
|
.Subscribe(_ => {
|
|||
|
MessageKit.Publish("全局", ("类型Btn", true));
|
|||
|
})
|
|||
|
.AddTo(this);
|
|||
|
}
|
|||
|
}
|