mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
ConsoleToScreen
ConsoleToScreen
This commit is contained in:
55
Assets/Scene/ConsoleToSceen.cs
Normal file
55
Assets/Scene/ConsoleToSceen.cs
Normal file
@@ -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<string> _lines = new List<string>();
|
||||
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);
|
||||
}
|
||||
}
|
11
Assets/Scene/ConsoleToSceen.cs.meta
Normal file
11
Assets/Scene/ConsoleToSceen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfe10a0a11028794aac9fd5ea811c3e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user