+ Add Discord webhook

This commit is contained in:
Jahnisse
2026-03-26 14:50:54 +01:00
parent 2798f35fbb
commit b8f12009ae
22 changed files with 574 additions and 27 deletions
+46
View File
@@ -0,0 +1,46 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
[InitializeOnLoad]
public class SceneNotifier
{
private static readonly string WebhookUrl = "http://n8n.homelab/webhook/unity-scene";
private static readonly string UserName = System.Environment.UserName;
private static readonly HttpClient Http = new HttpClient();
static SceneNotifier()
{
EditorSceneManager.sceneOpened += OnSceneOpened;
EditorSceneManager.sceneClosed += OnSceneClosed;
}
private static void OnSceneOpened(UnityEngine.SceneManagement.Scene scene, OpenSceneMode mode)
{
_ = SendNotification(scene.name, "opened");
}
private static void OnSceneClosed(UnityEngine.SceneManagement.Scene scene)
{
_ = SendNotification(scene.name, "closed");
}
private static async Task SendNotification(string sceneName, string action)
{
string json = $"{{\"scene\":\"{sceneName}\",\"user\":\"{UserName}\",\"action\":\"{action}\"}}";
try
{
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await Http.PostAsync(WebhookUrl, content);
Debug.Log($"[SceneNotifier] Sent: {json} — Status: {response.StatusCode}");
}
catch (System.Exception e)
{
Debug.LogWarning($"[SceneNotifier] Failed to notify: {e.Message}");
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7eb9dbf21e942834386d0e1946d5d245