| | |
| | | using UnityEngine; |
| | | using System.Collections; |
| | | using UnityEngine.UI; |
| | | using System.Collections.Generic; |
| | | using System; |
| | | |
| | | namespace Snxxz.UI |
| | | { |
| | | |
| | | public class DebugLogRecorder : MonoBehaviour |
| | | { |
| | | |
| | | [SerializeField] |
| | | Text m_LogPanel; |
| | | |
| | | List<LogData> logs = new List<LogData>(); |
| | | float timer = 0f; |
| | | |
| | | private void Awake() |
| | | { |
| | | Application.logMessageReceived += AddLogRenderer; |
| | | Application.logMessageReceivedThreaded += AddLogRenderer; |
| | | } |
| | | |
| | | private void OnEnable() |
| | | { |
| | | LogRenderer(); |
| | | } |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | timer += Time.deltaTime; |
| | | if (timer > 1f) |
| | | { |
| | | timer = 0f; |
| | | for (int i = logs.Count - 1; i >= 0; i--) |
| | | { |
| | | if (logs[i].dieTime < DateTime.Now) |
| | | { |
| | | logs.RemoveAt(i); |
| | | } |
| | | } |
| | | |
| | | LogRenderer(); |
| | | } |
| | | } |
| | | |
| | | private void OnDisable() |
| | | { |
| | | logs.Clear(); |
| | | } |
| | | |
| | | private void OnDestroy() |
| | | { |
| | | Application.logMessageReceived -= AddLogRenderer; |
| | | Application.logMessageReceivedThreaded -= AddLogRenderer; |
| | | } |
| | | |
| | | public void SetLogVisible() |
| | | { |
| | | Debug.developerConsoleVisible = !Debug.developerConsoleVisible; |
| | | } |
| | | |
| | | void AddLogRenderer(string _log, string _callStack, LogType _type) |
| | | { |
| | | if (!DebugUtility.Instance.debugAccount) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (!LocalSave.GetBool("DebugDrawAtGameView")) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | bool allow = false; |
| | | switch (_type) |
| | | { |
| | | case LogType.Log: |
| | | allow = DesignDebug.EnableLog || DesignDebug.EnableNet; |
| | | break; |
| | | case LogType.Warning: |
| | | allow = DesignDebug.EnableLogWarning; |
| | | break; |
| | | case LogType.Error: |
| | | case LogType.Exception: |
| | | case LogType.Assert: |
| | | allow = DesignDebug.EnableLogError; |
| | | break; |
| | | } |
| | | |
| | | if (!allow) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var content = string.Empty; |
| | | if (LocalSave.GetBool("DebugCallStack")) |
| | | { |
| | | content = _log + "\n" + _callStack; |
| | | } |
| | | else |
| | | { |
| | | content = _log; |
| | | } |
| | | |
| | | logs.Add(new LogData(_type, content, 5)); |
| | | if (logs.Count == 1) |
| | | { |
| | | timer = 0f; |
| | | } |
| | | |
| | | LogRenderer(); |
| | | } |
| | | |
| | | void LogRenderer() |
| | | { |
| | | var contents = string.Empty; |
| | | for (int i = logs.Count - 1; i >= 0; i--) |
| | | { |
| | | if (logs.Count - 1 == i) |
| | | { |
| | | contents += logs[i].content; |
| | | } |
| | | else |
| | | { |
| | | contents += "\n" + logs[i].content; |
| | | } |
| | | } |
| | | |
| | | if (contents.Length > 5000) |
| | | { |
| | | m_LogPanel.text = contents.Substring(contents.Length - 5000, 5000); |
| | | } |
| | | else |
| | | { |
| | | m_LogPanel.text = contents; |
| | | } |
| | | |
| | | } |
| | | |
| | | struct LogData |
| | | { |
| | | public string content; |
| | | public DateTime dieTime; |
| | | |
| | | public LogData(LogType _logType, string _content, int _seconds) |
| | | { |
| | | switch (_logType) |
| | | { |
| | | case LogType.Log: |
| | | this.content = "[Log]: " + _content; |
| | | break; |
| | | case LogType.Warning: |
| | | this.content = "[<color=yellow>Warning</color>]: " + _content; |
| | | break; |
| | | case LogType.Assert: |
| | | this.content = "[<color=red>Assert</color>]: " + _content; |
| | | break; |
| | | case LogType.Exception: |
| | | this.content = "[<color=red>Exception</color>]: " + _content; |
| | | break; |
| | | case LogType.Error: |
| | | this.content = "[<color=red>Error</color>]: " + _content; |
| | | break; |
| | | default: |
| | | this.content = _content; |
| | | break; |
| | | } |
| | | |
| | | this.dieTime = DateTime.Now + new TimeSpan(_seconds * TimeSpan.TicksPerSecond); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | using UnityEngine;
|
| | | using System.Collections;
|
| | | using UnityEngine.UI;
|
| | | using System.Collections.Generic;
|
| | | using System;
|
| | |
|
| | | namespace Snxxz.UI
|
| | | {
|
| | |
|
| | | public class DebugLogRecorder : MonoBehaviour
|
| | | {
|
| | |
|
| | | [SerializeField]
|
| | | Text m_LogPanel;
|
| | |
|
| | | List<LogData> logs = new List<LogData>();
|
| | | float timer = 0f;
|
| | |
|
| | | private void Awake()
|
| | | {
|
| | | }
|
| | |
|
| | | private void OnEnable()
|
| | | {
|
| | | LogRenderer();
|
| | | }
|
| | |
|
| | | private void LateUpdate()
|
| | | {
|
| | | timer += Time.deltaTime;
|
| | | if (timer > 1f)
|
| | | {
|
| | | timer = 0f;
|
| | | for (int i = logs.Count - 1; i >= 0; i--)
|
| | | {
|
| | | if (logs[i].dieTime < DateTime.Now)
|
| | | {
|
| | | logs.RemoveAt(i);
|
| | | }
|
| | | }
|
| | |
|
| | | LogRenderer();
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnDisable()
|
| | | {
|
| | | logs.Clear();
|
| | | }
|
| | |
|
| | | private void OnDestroy()
|
| | | {
|
| | | }
|
| | |
|
| | | public void SetLogVisible()
|
| | | {
|
| | | Debug.developerConsoleVisible = !Debug.developerConsoleVisible;
|
| | | }
|
| | |
|
| | | void AddLogRenderer(string _log, string _callStack, LogType _type)
|
| | | {
|
| | | if (!DebugUtility.Instance.debugAccount)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!LocalSave.GetBool("DebugDrawAtGameView"))
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | bool allow = false;
|
| | | switch (_type)
|
| | | {
|
| | | case LogType.Log:
|
| | | allow = DebugEx.EnableLog || DebugEx.EnableNetLog;
|
| | | break;
|
| | | case LogType.Warning:
|
| | | allow = DebugEx.EnableLogWarning;
|
| | | break;
|
| | | case LogType.Error:
|
| | | case LogType.Exception:
|
| | | case LogType.Assert:
|
| | | allow = DebugEx.EnableLogError;
|
| | | break;
|
| | | }
|
| | |
|
| | | if (!allow)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | var content = string.Empty;
|
| | | if (LocalSave.GetBool("DebugCallStack"))
|
| | | {
|
| | | content = _log + "\n" + _callStack;
|
| | | }
|
| | | else
|
| | | {
|
| | | content = _log;
|
| | | }
|
| | |
|
| | | logs.Add(new LogData(_type, content, 5));
|
| | | if (logs.Count == 1)
|
| | | {
|
| | | timer = 0f;
|
| | | }
|
| | |
|
| | | LogRenderer();
|
| | | }
|
| | |
|
| | | void LogRenderer()
|
| | | {
|
| | | var contents = string.Empty;
|
| | | for (int i = logs.Count - 1; i >= 0; i--)
|
| | | {
|
| | | if (logs.Count - 1 == i)
|
| | | {
|
| | | contents += logs[i].content;
|
| | | }
|
| | | else
|
| | | {
|
| | | contents += "\n" + logs[i].content;
|
| | | }
|
| | | }
|
| | |
|
| | | if (contents.Length > 5000)
|
| | | {
|
| | | m_LogPanel.text = contents.Substring(contents.Length - 5000, 5000);
|
| | | }
|
| | | else
|
| | | {
|
| | | m_LogPanel.text = contents;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | struct LogData
|
| | | {
|
| | | public string content;
|
| | | public DateTime dieTime;
|
| | |
|
| | | public LogData(LogType _logType, string _content, int _seconds)
|
| | | {
|
| | | switch (_logType)
|
| | | {
|
| | | case LogType.Log:
|
| | | this.content = "[Log]: " + _content;
|
| | | break;
|
| | | case LogType.Warning:
|
| | | this.content = "[<color=yellow>Warning</color>]: " + _content;
|
| | | break;
|
| | | case LogType.Assert:
|
| | | this.content = "[<color=red>Assert</color>]: " + _content;
|
| | | break;
|
| | | case LogType.Exception:
|
| | | this.content = "[<color=red>Exception</color>]: " + _content;
|
| | | break;
|
| | | case LogType.Error:
|
| | | this.content = "[<color=red>Error</color>]: " + _content;
|
| | | break;
|
| | | default:
|
| | | this.content = _content;
|
| | | break;
|
| | | }
|
| | |
|
| | | this.dieTime = DateTime.Now + new TimeSpan(_seconds * TimeSpan.TicksPerSecond);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | |
|