using System; using System.Collections.Generic; using System.Text; using System.Threading; using UnityEngine; using XUpdater; namespace XUtliPoolLib { public class XDebug : XSingleton { private int _OutputChannels = 0; private IPlatform _platform = null; private bool _showTimeStick = true; private bool _showLog = true; private StringBuilder _buffer = new StringBuilder(); private XDebug.LayerInfo[] m_LayerInfo = new XDebug.LayerInfo[] { new XDebug.LayerInfo(), new XDebug.LayerInfo() }; private int m_MaxLayer = 2; private bool m_record = false; private bool m_recordStart = false; private XDebug.RecordChannel m_RecordChannel = XDebug.RecordChannel.ENone; public enum RecordChannel { ENone, ENetwork, EResourceLoad } public enum RecordLayer { ELayer0, ELayer1, ENum } public class SizeInfo { public string Name = ""; public float Size = 0f; public int Count = 0; } public class LayerInfo { public string Name = ""; public Dictionary SizeInfoMap = new Dictionary(); public void Clear() { this.SizeInfoMap.Clear(); } } public XDebug() { this._OutputChannels = 5; } public void Init(IPlatform platform, XFileLog log) { this._platform = XSingleton.singleton.XPlatform; } public void AddLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null, XDebugColor color = XDebugColor.XDebug_None) { bool flag = this._platform != null && !this._platform.IsPublish(); if (flag) { this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, color); } } public void AddLog2(string format, params object[] args) { bool flag = this._showLog && this._platform != null && !this._platform.IsPublish(); if (flag) { this.AddLog(string.Format(format, args), null, null, null, null, null, XDebugColor.XDebug_None); } } public void AddLog(XDebugChannel channel, string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null, XDebugColor color = XDebugColor.XDebug_None) { bool flag = this._showLog && this._platform != null && !this._platform.IsPublish(); if (flag) { bool flag2 = (this._OutputChannels & (int)channel) > 0; if (flag2) { this._buffer.Length = 0; this._buffer.Append(log1).Append(log2).Append(log3).Append(log4).Append(log5).Append(log6); bool flag3 = color == XDebugColor.XDebug_Green; if (flag3) { this._buffer.Insert(0, ""); this._buffer.Append(""); } bool showTimeStick = this._showTimeStick; if (showTimeStick) { bool flag4 = Thread.CurrentThread.ManagedThreadId == XSingleton.singleton.ManagedThreadId; if (flag4) { this._buffer.Append(" (at Frame: ").Append(Time.frameCount).Append(" sec: ").Append(Time.realtimeSinceStartup.ToString("F3")).Append(')'); } else { bool flag5 = string.IsNullOrEmpty(Thread.CurrentThread.Name); if (flag5) { this._buffer.Append(" (from anonymous thread").Append(" with id ").Append(Thread.CurrentThread.ManagedThreadId).Append(")"); } else { this._buffer.Append(" (from thread ").Append(Thread.CurrentThread.Name).Append(" with id ").Append(Thread.CurrentThread.ManagedThreadId).Append(")"); } } } bool flag6 = color == XDebugColor.XDebug_Red; if (flag6) { Debug.LogError(this._buffer); } else { bool flag7 = color == XDebugColor.XDebug_Yellow; if (flag7) { Debug.LogWarning(this._buffer); } else { Debug.Log(this._buffer); } } } } } public void AddGreenLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null) { bool flag = this._platform != null && !this._platform.IsPublish(); if (flag) { this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, XDebugColor.XDebug_Green); } } public void AddWarningLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null) { bool flag = this._platform != null && !this._platform.IsPublish(); if (flag) { this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, XDebugColor.XDebug_Yellow); } } public void AddWarningLog2(string format, params object[] args) { bool flag = this._showLog && this._platform != null && !this._platform.IsPublish(); if (flag) { this.AddWarningLog(string.Format(format, args), null, null, null, null, null); } } public void AddErrorLog2(string format, params object[] args) { bool flag = this._showLog && this._platform != null && !this._platform.IsPublish(); if (flag) { this.AddErrorLog(string.Format(format, args), null, null, null, null, null); } } public void AddErrorLog(string log1, string log2 = null, string log3 = null, string log4 = null, string log5 = null, string log6 = null) { this._buffer.Length = 0; bool flag = Thread.CurrentThread.ManagedThreadId == XSingleton.singleton.ManagedThreadId; if (flag) { this._buffer.Append(log1).Append(log2).Append(log3).Append(log4).Append(log5).Append(log6).Append(" (at Frame: ").Append(Time.frameCount).Append(" sec: ").Append(Time.realtimeSinceStartup.ToString("F3")).Append(')'); } else { this._buffer.Append(log1).Append(log2).Append(log3).Append(log4).Append(log5).Append(log6); } XFileLog.AddCustomLog("AddErrorLog: " + this._buffer); this.AddLog(XDebugChannel.XDebug_Default, log1, log2, log3, log4, log5, log6, XDebugColor.XDebug_Red); } public override bool Init() { return true; } public override void Uninit() { } public void BeginProfile(string title) { } public void RegisterGroupProfile(string title) { } public void BeginGroupProfile(string title) { } public void EndProfile() { } public void EndGroupProfile(string title) { } public void InitProfiler() { } public void PrintProfiler() { } public void StartRecord(XDebug.RecordChannel channel) { this.m_record = true; this.m_recordStart = false; this.m_RecordChannel = channel; XDebug.RecordChannel recordChannel = this.m_RecordChannel; if (recordChannel != XDebug.RecordChannel.ENetwork) { if (recordChannel == XDebug.RecordChannel.EResourceLoad) { this.m_LayerInfo[0].Name = "SharedRes"; this.m_LayerInfo[1].Name = "Prefab"; } } else { this.m_LayerInfo[0].Name = "Recv"; this.m_LayerInfo[1].Name = "Send"; } } public void EndRecord() { this.m_record = false; this.m_recordStart = false; this.m_RecordChannel = XDebug.RecordChannel.ENone; } public void BeginRecord() { bool record = this.m_record; if (record) { this.m_recordStart = true; } } public void ClearRecord() { this.m_LayerInfo[0].Clear(); this.m_LayerInfo[1].Clear(); } public bool EnableRecord() { return this.m_recordStart; } public void AddPoint(uint key, string name, float size, int layer, XDebug.RecordChannel channel) { bool flag = this.m_recordStart && channel == this.m_RecordChannel && layer >= 0 && layer < this.m_MaxLayer; if (flag) { Dictionary sizeInfoMap = this.m_LayerInfo[layer].SizeInfoMap; XDebug.SizeInfo sizeInfo = null; bool flag2 = !sizeInfoMap.TryGetValue(key, out sizeInfo); if (flag2) { sizeInfo = new XDebug.SizeInfo(); sizeInfo.Name = name; sizeInfoMap.Add(key, sizeInfo); } sizeInfo.Count++; sizeInfo.Size += size; } } public void Print() { float num = 0f; for (int i = 0; i < this.m_MaxLayer; i++) { XSingleton.singleton.CleanStringCombine(); float num2 = 0f; XDebug.SizeInfo sizeInfo = null; XDebug.LayerInfo layerInfo = this.m_LayerInfo[i]; XSingleton.singleton.AppendString(layerInfo.Name, ":\r\n"); foreach (KeyValuePair keyValuePair in layerInfo.SizeInfoMap) { XDebug.SizeInfo value = keyValuePair.Value; XSingleton.singleton.AppendString(string.Format("Name:{0} Count:{1} Size:{2}\r\n", value.Name, value.Count, value.Size)); num += value.Size; num2 += value.Size; bool flag = sizeInfo == null || sizeInfo.Size < value.Size; if (flag) { sizeInfo = value; } } XSingleton.singleton.AddWarningLog(XSingleton.singleton.GetString(), null, null, null, null, null); bool flag2 = sizeInfo != null; if (flag2) { XSingleton.singleton.AddWarningLog2("max name:{0} Count:{1} Size:{2}", new object[] { sizeInfo.Name, sizeInfo.Count, sizeInfo.Size }); } XSingleton.singleton.AddWarningLog2("total {0} size:{1}", new object[] { layerInfo.Name, num2 }); } XSingleton.singleton.AddWarningLog("total size:", num.ToString(), null, null, null, null); } } }