TH1/Unity/Assets/Scripts/TH1_Logic/CrashSight/CrashSightManager.cs
2025-08-18 23:16:13 +08:00

83 lines
2.7 KiB
C#

/*
* @Author: 白哉
* @Description:
* @Date: 2025年07月03日 星期四 10:07:49
* @Modify:
*/
using Logic.Config;
using UnityEngine;
namespace Logic.CrashSight
{
public class CrashSightManager
{
public static CrashSightManager Instance => new CrashSightManager();
private CrashSightManager() { }
public void Initialize()
{
CrashSightAgent.ConfigCrashReporter(1);
// 设置上报的目标域名,请根据项目需求进行填写。(必填)
CrashSightAgent.ConfigCrashServerUrl("pc.crashsight.qq.com");
// 设置上报所指向的APP ID, 并进行初始化。APPID可以在管理端更多->产品设置->产品信息中找到。
CrashSightAgent.InitWithAppId("01076c49ce");
}
}
public class LogSystem
{
public static string Record = string.Empty;
private static string GenerateHashCode()
{
string deviceId = SystemInfo.deviceUniqueIdentifier;
string timestamp = System.DateTime.UtcNow.Ticks.ToString();
string combined = deviceId + timestamp;
using (var md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(combined);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
}
public static void LogError(string message, Object context = null)
{
#if !UNITY_EDITOR
CrashSightAgent.PrintLog(CSLogSeverity.LogError, message);
# endif
if (context!=null) Debug.LogError(message, context);
else Debug.LogError(message);
}
public static void LogWarning(string message, Object context = null)
{
#if !UNITY_EDITOR
CrashSightAgent.PrintLog(CSLogSeverity.LogWarning, message);
# endif
if (context!=null) Debug.LogWarning(message, context);
else Debug.LogWarning(message);
}
public static void LogInfo(string message, Object context = null)
{
#if !UNITY_EDITOR
CrashSightAgent.PrintLog(CSLogSeverity.LogInfo, message);
# endif
if (context!=null) Debug.Log(message, context);
else Debug.Log(message);
}
}
}