您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
72 行
2.2 KiB
72 行
2.2 KiB
using Backtrace.Unity;
|
|
using Backtrace.Unity.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Diagnostics;
|
|
public class TestBacktrace: MonoBehaviour
|
|
{
|
|
// Backtrace client instance
|
|
private BacktraceClient _backtraceClient;
|
|
|
|
void Start()
|
|
{
|
|
var serverUrl = "https://submit.backtrace.io/leoncheng/c37b512d36e8a673d1bf37ba13536e4a86632adac3cbf6fe5bf80778e3f2b670/json";
|
|
var gameObjectName = "_ErrorManager";
|
|
var databasePath = "${Application.persistentDataPath}/sample/backtrace/path";
|
|
var attributes = new Dictionary<string, string>() { { "my-super-cool-attribute-name", "attribute-value" } };
|
|
|
|
// use game object to initialize Backtrace integration
|
|
_backtraceClient = GameObject.Find(gameObjectName).GetComponent<BacktraceClient>();
|
|
//Read from manager BacktraceClient instance
|
|
var database = GameObject.Find(gameObjectName).GetComponent<BacktraceDatabase>();
|
|
|
|
// or initialize Backtrace integration directly in your source code
|
|
_backtraceClient = BacktraceClient.Initialize(
|
|
url: serverUrl,
|
|
databasePath: databasePath,
|
|
gameObjectName: gameObjectName,
|
|
attributes: attributes);
|
|
|
|
}
|
|
|
|
public void OnLogError()
|
|
{
|
|
Debug.LogError("Report LogError");
|
|
}
|
|
|
|
public void TriggerUnhandledException()
|
|
{
|
|
throw new Exception("Unhandled Exception");
|
|
}
|
|
|
|
public void TriggerHandledException()
|
|
{
|
|
try
|
|
{
|
|
// throw an exception here
|
|
throw new Exception();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
var report = new BacktraceReport(
|
|
exception: exception,
|
|
attributes: new Dictionary<string, string>() { { "key", "value" } },
|
|
attachmentPaths: new List<string>() { @"file_path_1", @"file_path_2" }
|
|
);
|
|
_backtraceClient.Send(report);
|
|
|
|
}
|
|
}
|
|
|
|
public void TriggerCrash()
|
|
{
|
|
//Utils.ForceCrash(ForcedCrashCategory.AccessViolation);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|