wangguan
2020-11-12 a7956acb794f93fc01e16963efe1f38743b110f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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) =>
            {
                m_logEntries.Add(string.Format("{0}\n{1}", condition, stackTrace));
            };
        }
 
        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()
        {
 
        }
    }
}