+ Add Discord webhook
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eb9dbf21e942834386d0e1946d5d245
|
||||
Reference in New Issue
Block a user