1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/Common/Scripts/MainLogicBase.cs

270 lines
8.3 KiB
C#

using _1;
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 Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using System.Threading;
using UniRx;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainLogicBase : SingletonMonobehaviour
{
public static bool isFirst = true;
protected UIGlobal GlobalPage { get => Page.GetUI<UIGlobal>("全局"); }
public Page Page { get => SendGetPage(); }
protected override void Awake()
{
base.Awake();
MessageKit
.GetSubscriber<string>()
.Subscribe(_ => {
isFirst = true;
SceneManager.LoadScene(1);
}, _ => _ == "返回首页"
)
.AddTo(this);
MessageKit
.GetSubscriber<string>()
.Subscribe(_ => {
SendPageSetUI("类型", true);
SceneManager.LoadScene(1);
//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);
//MessageKit.Publish("类型Input", "");
}, _ => _ == "返回类型"
)
.AddTo(this);
}
//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);
// 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);
// 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);
// 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);
// await ui.WaitAsync(token);
// await ReturnMoudleSelect();
// }
// #endregion
// // method
// // Set顶部标题
// void SetTopText(string value)
// {
// this.Send("SetTopText", value);
// }
// // 返回类型界面
// async UniTask ReturnMoudleSelect()
// {
// MessageKit.GetPublisher<string>()
// .Publish("返回类型");
// await UniTask.Yield();
// }
//}
[SerializeField]
[ReadOnly]
protected string _currentPageName;
public MainLogicBase SetCurrentPage<TPage>() where TPage : Page
{
_currentPageName = typeof(TPage).Name;
return this;
}
public Page SendGetPage()
{
var page = IoC.GetSingleton<PageController>().GetPage(0);
//var page = MessageKit.PublishFunc(_currentPageName, default(Page));
return page;
}
public void SendPageSetUI(string name, bool value)
{
this.Page.GetUI<Transform>(name).gameObject.SetActive(value);
//MessageKit.Publish(_currentPageName, (name, value));
}
public async UniTask SendPageWaitUI(string name, CancellationToken token)
{
await this.Page.WaitUI(name, token);
//await MessageKit.PublishAsync(_currentPageName, name, token);
}
#region Generic Send
public async UniTask SendPageWaitUI<TPage>(string name, CancellationToken token) where TPage : Page
{
await MessageKit.PublishAsync(typeof(TPage).Name, name, token);
}
public void SendPageSetUI<TPage>(string name, bool value)
{
MessageKit.Publish(typeof(TPage).Name, (name, value));
}
#endregion
}