forked from zxl/LaboratoryProtection
67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using Cysharp.Threading.Tasks;
|
|
|
|
using MessagePipe;
|
|
|
|
using PMaker.Await;
|
|
using PMaker.MessagePipe;
|
|
|
|
using System.Threading;
|
|
using System.Transactions;
|
|
|
|
using UniRx;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace PMaker.UI
|
|
{
|
|
public abstract partial class Page : BaseBehaviour, IPage
|
|
{
|
|
protected CancellationTokenSource _tokenSource;
|
|
|
|
protected virtual void OnEnable()
|
|
{
|
|
_tokenSource = new CancellationTokenSource();
|
|
}
|
|
|
|
protected virtual void OnDisable()
|
|
{
|
|
_tokenSource?.Cancel();
|
|
}
|
|
|
|
public virtual void Hide()
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
public virtual void Show()
|
|
{
|
|
this.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
// message
|
|
public abstract partial class Page
|
|
{
|
|
protected virtual void Awake()
|
|
{
|
|
MessageKit.GetAsyncSubscriber<string, string>()
|
|
.Subscribe(this.GetType().Name, async (_, token) => {
|
|
await this.WaitUI(_, token);
|
|
})
|
|
.AddTo(this);
|
|
|
|
MessageKit.GetSubscriber<string, (string name, bool value)>()
|
|
.Subscribe(this.GetType().Name, (_) => {
|
|
this.GetUI<Transform>(_.name).gameObject.SetActive(_.value);
|
|
})
|
|
.AddTo(this);
|
|
|
|
MessageKit.GetFuncSubscriber<string, Page>()
|
|
.Subscribe(this.GetType().Name, _ => {
|
|
_.value = this;
|
|
})
|
|
.AddTo(this);
|
|
}
|
|
}
|
|
} |