1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/_1实验室危险源/Scripts/MainLogic.cs

203 lines
6.8 KiB
C#
Raw Normal View History

2023-09-12 15:55:51 +08:00
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
using MessagePipe;
using PMaker.Await;
using PMaker.Await.UI;
using PMaker.DependencyInjection;
using PMaker.MessagePipe;
using PMaker.MessagePipe.Extension;
using PMaker.UI;
using System;
using System.Collections.Generic;
using System.Threading;
using UniRx;
using UnityEngine;
namespace _1
{
public class MainLogic : MainLogicBase
{
private async void Start()
{
var mainCancellationToken = this.GetCancellationTokenOnDestroy();
//var page1 = UIKit.GetPage<Page1>();
#region Init
// 流程初始化
var list = new List<Func<CancellationToken, UniTask>>()
{
_0,
_1,
_2,
_3,
_4,
};
// Wait类型选择
async UniTask<int> WaitMoudleSelect(CancellationToken token)
{
var value = await this.SendFuncAsync("类型Any", -1, token);
Debug.Log(value);
return value;
}
// 2.类型选择界面
async UniTask _1PageLogic()
{
var tokenSource = default(CancellationTokenSource);
tokenSource?.Cancel();
tokenSource = new CancellationTokenSource();
tokenSource.AddTo(mainCancellationToken);
SetTopText("实验室危险源");
SendPageSetUI("类型", true);
var index = await WaitMoudleSelect(tokenSource.Token);
SendPageSetUI("类型", false);
await list[index].Invoke(tokenSource.Token);
}
MessageKit.GetSubscriber<string, string>()
.Subscribe("类型Input", async _ => {
Debug.Log("类型选择");
var result = await _1PageLogic().SuppressCancellationThrow();
Debug.Log("类型选择IsCanceled: " + result);
});
#endregion
await MessageKit.PublishAsync("Reload", 0);
if (MainLogicBase.isFirst == true)
{
MainLogicBase.isFirst = false;
SetCurrentPage<Page1>();
// 1.首页
await SendPageWaitUI("首页", mainCancellationToken);
}
// 2.0 全局 通用
SendPageSetUI("全局", true);
SendPageSetUI("通用", true);
MessageKit.Publish("类型Input", "");
//await IoC.GetSingleton<SceneLoader>().LoadScene(0);//.Forget();
#region Logic
// 0.综合考核->实验报告->试验结束
async UniTask _0(CancellationToken token)
{
// 3.综合考核
await SendPageWaitUI("00综合考核", token);
// 4.实验报告?
await SendPageWaitUI("实验报告", token);
// 5.试验结束
Debug.Log("实验结束");
MessageKit.Publish("返回首页");
}
// 1.危险化学品
async UniTask _1(CancellationToken token)
{
var tips = new string[]
{
"化学品标签",
"化学品安全技术说明书(SDS)",
"危险化学品分类",
"全生命周期管理",
};
var ui = Page.GetUI<UISequence>("01危险化学品");
ui.current
.Where(_ => _ >= 0 && _ < tips.Length)
.Subscribe(_ => {
SetTopText(tips[_]);
})
.AddTo(this);
SendPageSetUI("类型", true);
await IoC.GetSingleton<SceneLoader>().LoadScene(0);
SendPageSetUI("类型", false);
await ui.WaitAsync(token);
await ReturnMoudleSelect();
}
// 2.管制化学品
async UniTask _2(CancellationToken token)
{
var tips = new string[]
{
"管制化学品",
"管制化学品控制",
};
var ui = Page.GetUI<UISequence>("02管制化学品");
ui.current
.Where(_ => _ >= 0 && _ < tips.Length)
.Subscribe(_ => {
SetTopText(tips[_]);
})
.AddTo(this);
await ui.WaitAsync(token);
await ReturnMoudleSelect();
}
// 3.危险设备
async UniTask _3(CancellationToken token)
{
var tips = new string[]
{
"一般危险设备",
"特种设备",
};
var ui = Page.GetUI<UISequence>("03危险设备");
ui.current
.Where(_ => _ >= 0 && _ < tips.Length)
.Subscribe(_ => {
SetTopText(tips[_]);
})
.AddTo(this);
SendPageSetUI("类型", true);
await IoC.GetSingleton<SceneLoader>().LoadScene(0);
SendPageSetUI("类型", false);
await ui.WaitAsync(token);
await ReturnMoudleSelect();
}
// 4.实验室废弃物
async UniTask _4(CancellationToken token)
{
var tips = new string[]
{
"实验室废弃物处理",
};
var ui = Page.GetUI<UISequence>("04实验室废弃物");
ui.current
.Where(_ => _ >= 0 && _ < tips.Length)
.Subscribe(_ => {
SetTopText(tips[_]);
})
.AddTo(this);
SendPageSetUI("类型", true);
await IoC.GetSingleton<SceneLoader>().LoadScene(0);
SendPageSetUI("类型", false);
await ui.WaitAsync(token);
await ReturnMoudleSelect();
}
#endregion
// method
// Set顶部标题
void SetTopText(string value)
{
this.Send("SetTopText", value);
}
// 返回类型界面
async UniTask ReturnMoudleSelect()
{
//await MessageKit.PublishAsync("Reload", 0);
MessageKit.GetPublisher<string>()
.Publish("返回类型");
await UniTask.Yield();
}
}
}
}