This commit is contained in:
CortexCore
2024-11-03 16:38:17 +08:00
parent 056e2cada5
commit 4ba741408d
4693 changed files with 2445 additions and 5443 deletions

View File

@@ -6,13 +6,22 @@ using BITKit;
using UnityEngine.UIElements;
using Cysharp.Threading.Tasks;
using System.Linq;
using System.Net.Http;
using System.Text;
using UnityEngine.Serialization;
namespace BITKit.UX
{
public sealed class UXDebuger : MonoBehaviour
{
[SerializeField] private Color textColor = Color.black;
[SerializeField]private GUIStyle style;
[SerializeReference, SubclassSelector] private IReference postApi;
[SerializeField] private bool hidePostLog;
private readonly StringBuilder _logBuilder=new();
private readonly HttpClient _httpClient = new();
private void OnEnable()
{
Application.logMessageReceivedThreaded += OnLog;
@@ -21,16 +30,36 @@ namespace BITKit.UX
{
Application.logMessageReceivedThreaded -= OnLog;
}
private void OnLog(string condition, string stacktrace, LogType type)
{
_logBuilder.Append(condition);
_logBuilder.AppendLine(condition);
if (type is LogType.Error or LogType.Exception)
{
_logBuilder.AppendLine(stacktrace);
}
if (string.IsNullOrEmpty(postApi?.Value) is false)
{
try
{
_httpClient.PostAsync(postApi.Value, new StringContent(_logBuilder.ToString())).AsUniTask()
.Forget();
}
catch (Exception)
{
if (hidePostLog) return;
throw;
}
}
}
private void OnGUI()
{
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
GUILayout.BeginArea(new Rect(120, 120, Screen.width, Screen.height));
GUILayout.BeginVertical();
GUILayout.Label(_logBuilder.ToString());
//颜色更改为黑色
GUI.color = textColor;
GUILayout.Label(_logBuilder.ToString(),style);
GUILayout.EndVertical();
GUILayout.EndArea();
}