using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
namespace KTGMGemClient
|
{
|
public class ErrorLogOnGUIMyTools : MonoBehaviour
|
{
|
private List<string> m_logEntries = new List<string>();
|
|
private bool m_IsVisible = false;
|
|
private Rect m_WindowRect = new Rect(0, 0, Screen.width, Screen.height);
|
|
private Vector2 m_scrollPositionText = Vector2.zero;
|
|
private void Start()
|
{
|
DontDestroyOnLoad(this);
|
Application.logMessageReceived += (string condition, string stackTrace, LogType type) =>
|
{
|
if (type == LogType.Error)
|
{
|
m_logEntries.Add(string.Format("{0}\n{1}", condition, stackTrace));
|
m_IsVisible = true;
|
}
|
};
|
}
|
|
void ConsoleWindow(int windowID)
|
{
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("Clear", GUILayout.MaxWidth(100), GUILayout.MaxHeight(50)))
|
{
|
m_logEntries.Clear();
|
}
|
if (GUILayout.Button("Close", GUILayout.MaxWidth(100), GUILayout.MaxHeight(50)))
|
{
|
m_IsVisible = false;
|
}
|
GUILayout.EndHorizontal();
|
|
m_scrollPositionText = GUILayout.BeginScrollView(m_scrollPositionText);
|
// GUILayout.BeginScrollView(new Rect(0, 0, Screen.width - 200, Screen.height), new Vector2(0, 100), new Rect(0, 0, Screen.width, Screen.height), true, true);
|
|
GUI.skin.textArea.fontSize = 30;//调整字体
|
foreach (var entry in m_logEntries)
|
{
|
Color color = GUI.contentColor;
|
GUI.contentColor = Color.white;
|
GUILayout.TextArea(entry);
|
GUI.contentColor = color;
|
}
|
GUILayout.EndScrollView();
|
}
|
|
private void OnGUI()
|
{
|
GUILayout.BeginArea(new Rect(5, 460, 150, 300));
|
if (GUILayout.Button("Debug", GUILayout.Width(150), GUILayout.Height(70)))
|
m_IsVisible = !m_IsVisible;
|
GUILayout.EndArea();
|
|
if (m_IsVisible)
|
{
|
m_WindowRect = GUILayout.Window(0, m_WindowRect, ConsoleWindow, "Console");
|
}
|
}
|
|
/// <summary>
|
/// Update is called every frame, if the MonoBehaviour is enabled.
|
/// </summary>
|
void Update()
|
{
|
|
}
|
}
|
}
|