using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class StageLoadTimeOutCatcher : MonoBehaviour { const int timeOut = 20;//秒 public static ProtocolRecorder got0102Time; public static ProtocolRecorder gotA126Time; public static ProtocolRecorder gotA127Time; public static ProtocolRecorder got0109Time; public static ProtocolRecorder send0107Time; public static StageLoadTimeOutCatcher Begin(int stageId) { var go = new GameObject("StageLoadTimeOutCatcher"); var catcher = go.AddMissingComponent(); 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 = StringUtility.Contact(stageId, "地图加载超时"); var description = StringUtility.Contact( "开始时间:", startTime.ToString("HH:mm:ss"), ";", "超时时间:", DateTime.Now.ToString("HH:mm:ss"), "0102记录:", got0102Time.ToString(), ";", "A126记录:", gotA126Time.ToString(), ";", "A127记录:", gotA127Time.ToString(), ";", "0109记录:", got0109Time.ToString(), ";", "0107记录:", send0107Time.ToString()); ExceptionCatcher.ReportException(title, description); Stop(); } } public static void RecordProtocol(GameNetSystem.SocketType 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; default: break; } try { var title = StringUtility.Contact("地图加载记录-->封包编号:", number); var description = StringUtility.Contact(recorder.ToString(), "玩家:", PlayerDatas.Instance.baseData.PlayerName); ExceptionCatcher.ReportException(title, description); } catch (System.Exception ex) { } } public struct ProtocolRecorder { public string number; public DateTime time; public GameNetSystem.SocketType socketType; public ProtocolRecorder(string number, DateTime time, GameNetSystem.SocketType socketType) { this.number = number; this.time = time; this.socketType = socketType; } public override string ToString() { return StringUtility.Contact("封包:", number, ";", "时间:", time.ToString("HH:mm:ss"), ";", "服务器:", socketType); } } }