diff --git a/Assets/Scene/ConsoleToSceen.cs b/Assets/Scene/ConsoleToSceen.cs new file mode 100644 index 00000000..be5c2af8 --- /dev/null +++ b/Assets/Scene/ConsoleToSceen.cs @@ -0,0 +1,55 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ConsoleToSceen : MonoBehaviour +{ + const int maxLines = 50; + const int maxLineLength = 120; + private string _logStr = ""; + + GUIStyle titleStyle2 = new GUIStyle(); + + private readonly List _lines = new List(); + void OnEnable() { Application.logMessageReceived += Log; } + void OnDisable() { Application.logMessageReceived -= Log; } + void Update() { } + + public void Log(string logString, string stackTrace, LogType type) + { + foreach (var line in logString.Split('\n')) + { + if (line.Length <= maxLineLength) + { + _lines.Add(line); + continue; + } + var lineCount = line.Length / maxLineLength + 1; + for (int i = 0; i < lineCount; i++) + { + if ((i + 1) * maxLineLength <= line.Length) + { + _lines.Add(line.Substring(i * maxLineLength, maxLineLength)); + } + else + { + _lines.Add(line.Substring(i * maxLineLength, line.Length - i * maxLineLength)); + } + } + } + if (_lines.Count > maxLines) + { + _lines.RemoveRange(0, _lines.Count - maxLines); + } + _logStr = string.Join("\n", _lines); + } + + void OnGUI() + { + titleStyle2.fontSize = 20; + titleStyle2.normal.textColor = Color.white; + GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, + new Vector3(Screen.width / 1920f, Screen.height / 800.0f, 1.0f)); + GUI.Label(new Rect(10, 10, 800, 370), _logStr, titleStyle2); + } +} \ No newline at end of file diff --git a/Assets/Scene/ConsoleToSceen.cs.meta b/Assets/Scene/ConsoleToSceen.cs.meta new file mode 100644 index 00000000..75cb2707 --- /dev/null +++ b/Assets/Scene/ConsoleToSceen.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dfe10a0a11028794aac9fd5ea811c3e4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scene/TEngine-Demo.unity b/Assets/Scene/TEngine-Demo.unity index f49ad6b9..eda171cd 100644 --- a/Assets/Scene/TEngine-Demo.unity +++ b/Assets/Scene/TEngine-Demo.unity @@ -213,6 +213,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1297425163} + - component: {fileID: 1297425165} - component: {fileID: 1297425164} m_Layer: 0 m_Name: TEngine @@ -247,3 +248,15 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 869b1b77e2356f14a86cbb2646bc4032, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &1297425165 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1297425162} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dfe10a0a11028794aac9fd5ea811c3e4, type: 3} + m_Name: + m_EditorClassIdentifier: