少年修仙传客户端代码仓库
client_linchunjie
2018-09-21 edfd535734a7adab6d0f24c863149ed63bcd37c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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();
        }
    }
 
}