using System; using asap.core; using game; using GameCore; using UniRx; using UnityEngine; public class AutoRestart { private CompositeDisposable disposable = new CompositeDisposable(); private string lastUnloadedActId; public void Init() { GContext.OnEvent().Subscribe(OnActUnloaded).AddTo(disposable); GContext.OnEvent().Subscribe(OnActLoaded).AddTo(disposable); } public void Dispose() { disposable.Dispose(); disposable = null; } void OnActUnloaded(ActUnloadedEvent evt) { Debug.Log($"[AutoRestart::OnActUnloaded] {evt.actID}"); lastUnloadedActId = evt.actID; } void OnActLoaded(ActLoadedEvent evt) { var lastUnloadedActId = this.lastUnloadedActId; this.lastUnloadedActId = null; Debug.Log($"[AutoRestart::OnActLoaded] {evt.act.Id}"); if (lastUnloadedActId == "BuildAct" && evt.act.Id == "FishingAct") { Debug.Log($"[AutoRestart::OnActLoaded] Restart"); var userService = GContext.container.Resolve(); var config = GContext.container.Resolve(); if (userService == null || !userService.IsLogin || config == null) return; var loginTime = userService.LoginTime; var duration = DateTime.UtcNow - loginTime; if (duration.TotalDays >= 3 && config.Get("GM", "0") == "0") { RebootAlert(); } } } private async void RebootAlert() { GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel); var noticeConfirmPopupPanel = go.GetComponent(); string title = LocalizationMgr.GetText("UI_NoticePopupPanel_3"); string info = LocalizationMgr.GetText("UI_NoticePopupPanel_4"); string label = LocalizationMgr.GetText("UI_COMMON_confirm"); noticeConfirmPopupPanel.Init(1, title, info, onClickLeft: Reboot, onClose: Reboot, btn_left_text: label); } private async void Reboot() { QuitStage.Logout = true; await GContext.container.Resolve().SwitchStageAsync("QuitStage"); } }