备份CatanBuilding瘦身独立工程
This commit is contained in:
90
Assets/Scripts/Services/RTServiceBgFgManager.cs
Normal file
90
Assets/Scripts/Services/RTServiceBgFgManager.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using game;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
|
||||
public class RTServiceBgFgManager : MonoBehaviour
|
||||
{
|
||||
public static bool keepAlive = false;
|
||||
|
||||
private async void OnApplicationFocus(bool focus)
|
||||
{
|
||||
if (focus)
|
||||
{
|
||||
var rtService = GContext.container.Resolve<IRTService>();
|
||||
var userService = GContext.container.Resolve<IUserService>();
|
||||
var mailService = GContext.container.Resolve<IInGameMailService>();
|
||||
if(rtService != null && userService != null && userService.IsLogin)
|
||||
{
|
||||
if(await NeedReboot())
|
||||
{
|
||||
RebootAlert();
|
||||
}
|
||||
else {
|
||||
try
|
||||
{
|
||||
await rtService.Connect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
await mailService.FetchMail();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApplicationPause(bool pause)
|
||||
{
|
||||
if (pause && !keepAlive)
|
||||
{
|
||||
var rtService = GContext.container.Resolve<IRTService>();
|
||||
var userService = GContext.container.Resolve<IUserService>();
|
||||
if(rtService != null && userService != null && userService.IsLogin)
|
||||
{
|
||||
rtService.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void RebootAlert()
|
||||
{
|
||||
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
||||
var noticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
||||
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: RootCtx.ExitGame, onClose: RootCtx.ExitGame, btn_left_text: label);
|
||||
}
|
||||
|
||||
private async Task<bool> NeedReboot()
|
||||
{
|
||||
var userService = GContext.container.Resolve<IUserService>();
|
||||
var config = GContext.container.Resolve<IConfig>();
|
||||
|
||||
if(userService == null || !userService.IsLogin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config == null) return false;
|
||||
|
||||
var loginTime = userService.LoginTime;
|
||||
var duration = ZZTimeHelper.UtcNow() - loginTime;
|
||||
if(duration.Days >=1)
|
||||
{
|
||||
var localVer = VersionTool.FromLocal();
|
||||
var remoteConfig = await ConfigExtension.GetRemoteConfig();
|
||||
if(remoteConfig == null) return false;
|
||||
var remoteVerStr = remoteConfig[GConstant.K_Ver];
|
||||
var remoteVer = VersionTool.FromString(remoteVerStr);
|
||||
return remoteVer > localVer || remoteVer.Build != localVer.Build;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user