1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/_2实验室的防护与应急/Scripts/MainLogic.cs

253 lines
8.9 KiB
C#
Raw Permalink 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.Extension;
using PMaker.MessagePipe;
using PMaker.MessagePipe.Extension;
using PMaker.UI;
using System;
using System.Collections.Generic;
using System.Threading;
using UniRx;
using UnityEngine;
namespace _2
{
public class MainLogic : MainLogicBase
{
private async void Start()
{
var mainCancellationToken = this.GetCancellationTokenOnDestroy();
#region Init
// 流程初始化
var list = new List<Func<CancellationToken, UniTask>>()
{
_0,
_1,
_2,
};
// 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 = CancellationTokenSource.CreateLinkedTokenSource(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<Page2>();
// 1.首页
await SendPageWaitUI("首页", mainCancellationToken);
}
else
{
SetCurrentPage<Page2>();
}
// 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)
{
SetTopText("实验室防护系统");
var tips = new string[]
{
"实验室的防护与应急虚拟",
};
var ui = Page.GetUI<AwaitBehaviour>("01实验室的防护与应急虚拟");
//ui.current
// .Where(_ => _ >= 0 && _ < tips.Length)
// .Subscribe(_ => {
// SetTopText(tips[_]);
// })
// .AddTo(this);
await ui.WaitAsync(token);
await ReturnMoudleSelect();
}
// 2.现场事故应急处置模块
async UniTask _2(CancellationToken token)
{
var sublist = new List<Func<CancellationToken, UniTask>>()
{
_2_1,
_2_2,
_2_3,
_2_4,
};
{
while (token.IsCancellationRequested != true)
{
SetTopText("现场事故应急处置模块");
Page.ShowUI("02现场事故应急处置模块");
var moudleSelect = Page.GetUI<UIMoudleIndexGetter>("02现场事故应急处置模块/模块选择");
moudleSelect.gameObject.SetActive(true);
var index = await moudleSelect.WaitIndexAsync(token);
if (index is 3)
{
await sublist[index].Invoke(token);
continue;
}
else
{
moudleSelect.gameObject.SetActive(false);
await sublist[index].Invoke(token);
await ReturnMoudleSelectSub();
continue;
}
}
}
//Page.HideUI("02现场事故应急处置模块");
}
// 2.1.现场急救具体处置
async UniTask _2_1(CancellationToken token)
{
var tips = new string[]
{
"现场急救具体处置",
};
var ui = Page.GetUI<UISequence>("02现场事故应急处置模块/01现场急救具体处置");
ui.current
.Where(_ => _ >= 0 && _ < tips.Length)
.Subscribe(_ => { SetTopText(tips[_]); })
.AddTo(this);
await ui.WaitAsync(token);
//await ReturnMoudleSelect();
}
// 2.2.危化品泄露应急处置-待制作
async UniTask _2_2(CancellationToken token)
{
var ui = Page.GetUI<AwaitBehaviour>("02现场事故应急处置模块/02危化品泄露应急处置-待完善");
SetTopText("危化品泄露应急处置");
await ui.WaitAsync(token);
// await ReturnMoudleSelect();
//await GlobalPage.ShowTip_2Async("待制作",
// cancellationToken: token,
// onSelect: new Func<CancellationToken, UniTask>[]
// {
// async token => {
// await UniTask.Yield();
// },
// async token => {
// await UniTask.Yield();
// },
// });
//await ReturnMoudleSelect();
}
// 2.3.气瓶泄漏应急处置
async UniTask _2_3(CancellationToken token)
{
var tips = new string[]
{
"气瓶泄漏应急处置",
};
var ui = Page.GetUI<UISequence>("02现场事故应急处置模块/03气瓶泄漏应急处置");
ui.current
.Where(_ => _ >= 0 && _ < tips.Length)
.Subscribe(_ => { SetTopText(tips[_]); })
.AddTo(this);
await ui.WaitAsync(token);
//await ReturnMoudleSelect();
}
// 2.4.气瓶泄漏应急处置-待补充
async UniTask _2_4(CancellationToken token)
{
await GlobalPage.ShowTip_2Async("待补充",
cancellationToken: token,
onSelect: new Func<CancellationToken, UniTask>[]
{
async token => { await UniTask.Yield(); },
async token => { await UniTask.Yield(); },
});
//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();
}
// 返回2级类型界面
async UniTask ReturnMoudleSelectSub()
{
await MessageKit.PublishAsync("Reload", 0);
var page = this.Page;
foreach (var item in page.transform.Children())
{
item.gameObject.SetActive(false);
}
page.transform.Find("全局").gameObject.SetActive(true);
page.transform.Find("通用").gameObject.SetActive(true);
}
}
}
}