init project

This commit is contained in:
2024-04-03 15:13:12 +08:00
commit da15a24596
44 changed files with 2926 additions and 0 deletions

1080
Runtime/BuglyAgent.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be621fe31508b4f2ab134ee879ec97b4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

27
Runtime/BuglyCallback.cs Normal file
View File

@@ -0,0 +1,27 @@
// ----------------------------------------
//
// BuglyCallbackDelegate.cs
//
// Author:
// Yeelik, <bugly@tencent.com>
//
// Copyright (c) 2015 Bugly, Tencent. All rights reserved.
//
// ----------------------------------------
//
using UnityEngine;
using System.Collections;
public abstract class BuglyCallback
{
// The delegate of callback handler which Call the Application.RegisterLogCallback(Application.LogCallback)
/// <summary>
/// Raises the application log callback handler event.
/// </summary>
/// <param name="condition">Condition.</param>
/// <param name="stackTrace">Stack trace.</param>
/// <param name="type">Type.</param>
public abstract void OnApplicationLogCallbackHandler (string condition, string stackTrace, LogType type);
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 78e76f643d1884dcab602d5fe79b08e1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

80
Runtime/BuglyInit.cs Normal file
View File

@@ -0,0 +1,80 @@
// ----------------------------------------
//
// BuglyInit.cs
//
// Author:
// Yeelik, <bugly@tencent.com>
//
// Copyright (c) 2015 Bugly, Tencent. All rights reserved.
//
// ----------------------------------------
//
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BuglyInit : MonoBehaviour
{
/// <summary>
/// Your Bugly App ID. Every app has a special identifier that allows Bugly to associate error monitoring data with your app.
/// Your App ID can be found on the "Setting" page of the app you are trying to monitor.
/// </summary>
/// <example>A real App ID looks like this: 90000xxxx</example>
private const string BuglyAppID = "YOUR APP ID GOES HERE";
void Awake ()
{
// Enable the debug log print
BuglyAgent.ConfigDebugMode (false);
// Config default channel, version, user
BuglyAgent.ConfigDefault (null, null, null, 0);
// Config auto report log level, default is LogSeverity.LogError, so the LogError, LogException log will auto report
BuglyAgent.ConfigAutoReportLogLevel (LogSeverity.LogError);
// Config auto quit the application make sure only the first one c# exception log will be report, please don't set TRUE if you do not known what are you doing.
BuglyAgent.ConfigAutoQuitApplication (false);
// If you need register Application.RegisterLogCallback(LogCallback), you can replace it with this method to make sure your function is ok.
BuglyAgent.RegisterLogCallback (null);
// Init the bugly sdk and enable the c# exception handler.
BuglyAgent.InitWithAppId (BuglyAppID);
// TODO Required. If you do not need call 'InitWithAppId(string)' to initialize the sdk(may be you has initialized the sdk it associated Android or iOS project),
// please call this method to enable c# exception handler only.
BuglyAgent.EnableExceptionHandler ();
// TODO NOT Required. If you need to report extra data with exception, you can set the extra handler
BuglyAgent.SetLogCallbackExtrasHandler (MyLogCallbackExtrasHandler);
Destroy (this);
}
// Extra data handler to packet data and report them with exception.
// Please do not do hard work in this handler
static Dictionary<string, string> MyLogCallbackExtrasHandler ()
{
// TODO Test log, please do not copy it
BuglyAgent.PrintLog (LogSeverity.Log, "extra handler");
// TODO Sample code, please do not copy it
Dictionary<string, string> extras = new Dictionary<string, string> ();
extras.Add ("ScreenSolution", string.Format ("{0}x{1}", Screen.width, Screen.height));
extras.Add ("deviceModel", SystemInfo.deviceModel);
extras.Add ("deviceName", SystemInfo.deviceName);
extras.Add ("deviceType", SystemInfo.deviceType.ToString ());
extras.Add ("deviceUId", SystemInfo.deviceUniqueIdentifier);
extras.Add ("gDId", string.Format ("{0}", SystemInfo.graphicsDeviceID));
extras.Add ("gDName", SystemInfo.graphicsDeviceName);
extras.Add ("gDVdr", SystemInfo.graphicsDeviceVendor);
extras.Add ("gDVer", SystemInfo.graphicsDeviceVersion);
extras.Add ("gDVdrID", string.Format ("{0}", SystemInfo.graphicsDeviceVendorID));
extras.Add ("graphicsMemorySize", string.Format ("{0}", SystemInfo.graphicsMemorySize));
extras.Add ("systemMemorySize", string.Format ("{0}", SystemInfo.systemMemorySize));
extras.Add ("UnityVersion", Application.unityVersion);
BuglyAgent.PrintLog (LogSeverity.LogInfo, "Package extra data");
return extras;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a717f6955eddf4463ad541714a1b5483
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

91
Runtime/CrashConfig.cs Normal file
View File

@@ -0,0 +1,91 @@
using System;
using System.IO;
using UnityEngine;
namespace Runtime
{
[CreateAssetMenu (menuName = "CrashConfig")]
public class CrashConfig : ScriptableObject
{
private const string BuglyGUID = "BuglyGUID";
[SerializeField] private string BuglyAppID;
[SerializeField] private string BuglyChannel;
[SerializeField] private bool HasDebugMode;
[SerializeField] private bool EnableCrashReport;
public event Action<string, string, LogType> LogCallbackEvent;
public bool HasInit => this._hasInit;
private bool _hasInit;
private static CrashConfig _instance;
private static CrashConfig Instance
{
get
{
if (_instance == null)
{
_instance = Resources.Load<CrashConfig> (nameof(CrashConfig));
}
#if UNITY_EDITOR
if (_instance == null)
{
_instance = CreateInstance<CrashConfig> ();
// 自定义资源保存路径
string path = "Assets/Resources";
//如果项目总不包含该路径,创建一个
if (!Directory.Exists (path))
{
Directory.CreateDirectory (path);
}
UnityEditor.AssetDatabase.CreateAsset (_instance, path + $"/{nameof(CrashConfig)}.asset");
UnityEditor.AssetDatabase.Refresh ();
}
#endif
return _instance;
}
}
[RuntimeInitializeOnLoadMethod (RuntimeInitializeLoadType.AfterSceneLoad)]
private static void OnEnableCrashReport ()
{
if (Instance != null && Instance.EnableCrashReport)
{
Instance.InitCrash ();
}
}
private void InitCrash ()
{
if (this._hasInit)
{
return;
}
this._hasInit = true;
var buglyGuid = PlayerPrefs.HasKey (BuglyGUID) ? PlayerPrefs.GetString (BuglyGUID) : Guid.NewGuid ().ToString ();
PlayerPrefs.SetString (BuglyGUID, buglyGuid);
// 开启SDK的日志打印发布版本请务必关闭
if (this.HasDebugMode)
{
BuglyAgent.ConfigDebugMode (true);
}
// 注册日志回调,替换使用 'Application.RegisterLogCallback(Application.LogCallback)'注册日志回调的方式
BuglyAgent.RegisterLogCallback (OnLogCallBack);
BuglyAgent.ConfigDefault (this.BuglyChannel, Application.version , buglyGuid , 0);
BuglyAgent.InitWithAppId (this.BuglyAppID);
// 如果你确认已在对应的iOS工程或Android工程中初始化SDK那么在脚本中只需启动C#异常捕获上报功能即可
BuglyAgent.EnableExceptionHandler ();
}
private void OnLogCallBack (string condition, string stacktrace, LogType type)
{
this.LogCallbackEvent?.Invoke (condition, stacktrace, type);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 629b16a8ebee41a2b7e74748deb97933
timeCreated: 1712026840

View File

@@ -0,0 +1,3 @@
{
"name": "CrashRuntime"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 65e2e7312783df74897ad85f7b1afc1c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: