using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
public class StageLoadTimeOutCatcher : MonoBehaviour
|
{
|
|
const int timeOut = 20;//秒
|
public static DateTime got0109Time = DateTime.MinValue;
|
|
public static StageLoadTimeOutCatcher Begin(int stageId)
|
{
|
var go = new GameObject("StageLoadTimeOutCatcher");
|
var catcher = go.AddMissingComponent<StageLoadTimeOutCatcher>();
|
catcher.stageId = stageId;
|
|
DontDestroyOnLoad(go);
|
return catcher;
|
}
|
|
public int stageId = 0;
|
DateTime startTime;
|
|
private void Awake()
|
{
|
startTime = DateTime.Now;
|
}
|
|
public void Stop()
|
{
|
if (this.gameObject != null)
|
{
|
Destroy(this.gameObject);
|
}
|
}
|
|
void Update()
|
{
|
if (DateTime.Now > startTime + new TimeSpan(timeOut * TimeSpan.TicksPerSecond))
|
{
|
var title = "地图加载超时";
|
var description = StringUtility.Contact(
|
"加载地图:", stageId, ";",
|
"开始时间:", startTime.ToString("HH:mm:ss"), ";",
|
"超时时间:", DateTime.Now.ToString("HH:mm:ss"),
|
"服务器是否准备完毕:", StageManager.Instance.isServerPreparing,
|
"上一次接收到0109的时间:", got0109Time);
|
|
ExceptionCatcher.ReportException(title, description);
|
Stop();
|
}
|
}
|
|
}
|