You've already forked Dpr-ScriptsOnly
mirror of
https://github.com/izzy2lost/Dpr-ScriptsOnly.git
synced 2026-03-10 11:49:05 -07:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using System.Collections;
|
|
using SmartPoint.AssetAssistant;
|
|
|
|
namespace Dpr
|
|
{
|
|
public class LogSender : SingletonMonoBehaviour<LogSender>
|
|
{
|
|
private string _webhookUrl;
|
|
|
|
public void Init(Sequencer sequencer, string webhookUrl)
|
|
{
|
|
_webhookUrl = webhookUrl;
|
|
}
|
|
|
|
public void Log(string message)
|
|
{
|
|
// Output to the Unity console
|
|
Debug.Log(message);
|
|
|
|
if (UnityEditor.EditorApplication.isPlaying && StartupSettings.webhookInEditMode)
|
|
{
|
|
// Send to the webhook
|
|
StartCoroutine(SendToWebhook(message));
|
|
}
|
|
}
|
|
|
|
private IEnumerator SendToWebhook(string message)
|
|
{
|
|
string json = "{\"content\": \"" + message + "\"}";
|
|
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(json);
|
|
|
|
using (UnityWebRequest www = new UnityWebRequest(_webhookUrl, "POST"))
|
|
{
|
|
www.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("Content-Type", "application/json");
|
|
|
|
yield return www.SendWebRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|