using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
public class StageLoadTimeOutCatcher : MonoBehaviour
|
{
|
public static ProtocolRecorder got0102Time;
|
public static ProtocolRecorder gotA126Time;
|
public static ProtocolRecorder gotA127Time;
|
public static ProtocolRecorder got0109Time;
|
public static ProtocolRecorder got0403Time;
|
public static ProtocolRecorder send0107Time;
|
|
static StageLoadTimeOutCatcher timeOutCatcher;
|
|
public int stageId = 0;
|
public DateTime startTime;
|
|
private void Awake()
|
{
|
startTime = DateTime.Now;
|
}
|
|
public static void Begin(int stageId)
|
{
|
if (timeOutCatcher != null)
|
{
|
DestroyImmediate(timeOutCatcher.gameObject);
|
timeOutCatcher = null;
|
}
|
|
var go = new GameObject("StageLoadTimeOutCatcher");
|
var catcher = go.AddMissingComponent<StageLoadTimeOutCatcher>();
|
catcher.stageId = stageId;
|
timeOutCatcher = catcher;
|
DontDestroyOnLoad(go);
|
}
|
|
public static void Stop()
|
{
|
if (timeOutCatcher != null)
|
{
|
DestroyImmediate(timeOutCatcher.gameObject);
|
timeOutCatcher = null;
|
}
|
}
|
|
public static void ReportLoadingOverTime()
|
{
|
if (timeOutCatcher != null)
|
{
|
DestroyImmediate(timeOutCatcher.gameObject);
|
timeOutCatcher = null;
|
}
|
}
|
|
public static void RecordProtocol(ServerType socketType, string number, DateTime time)
|
{
|
var recorder = new ProtocolRecorder(number, time, socketType);
|
switch (number)
|
{
|
case "0102":
|
got0102Time = recorder;
|
break;
|
case "A126":
|
gotA126Time = recorder;
|
break;
|
case "A127":
|
gotA127Time = recorder;
|
break;
|
case "0109":
|
got0109Time = recorder;
|
break;
|
case "0107":
|
send0107Time = recorder;
|
break;
|
case "0403":
|
got0403Time = recorder;
|
break;
|
default:
|
break;
|
}
|
}
|
|
public struct ProtocolRecorder
|
{
|
public string number;
|
public DateTime time;
|
public ServerType socketType;
|
|
public ProtocolRecorder(string number, DateTime time, ServerType socketType)
|
{
|
this.number = number;
|
this.time = time;
|
this.socketType = socketType;
|
}
|
|
public override string ToString()
|
{
|
return StringUtility.Contact("封包:", number, ";", "时间:", time.ToString("HH:mm:ss"), ";", "服务器:", socketType);
|
}
|
}
|
|
}
|