Files
daluandou/.codely.packages/cn.tuanjie.codely.bridge@1.0.85-47f31100/Editor/Bridge/Notifier/SelectionChangedNotifier.cs
T
huadexuan 13d0c80335 ```
chore(bridge): 删除桥接包的提交记录和Git属性配置

删除了 .codely-bridge-commit 文件中存储的提交哈希值
移除了 .gitattributes 文件中的行结束符配置规则
```
2026-09-24 21:41:14 +08:00

58 lines
1.7 KiB
C#

using System;
using Codely.Newtonsoft.Json.Linq;
using UnityEditor;
using UnityTcp.Editor.Helpers;
namespace UnityTcp.Editor.Notifier
{
/// <summary>
/// Broadcasts the current Editor selection to notifier clients whenever it
/// changes. The emitted payload mirrors the structure returned by
/// <see cref="UnityTcp.Editor.Tools.ManageEditor"/>'s get_selection action.
/// </summary>
[InitializeOnLoad]
public static class SelectionChangedNotifier
{
private const string EventType = "selection_changed";
private static bool _flushScheduled;
static SelectionChangedNotifier()
{
if (EditorAutomationGuard.ShouldSkipBridgeAutoStart()) return;
Selection.selectionChanged += OnSelectionChanged;
}
private static void OnSelectionChanged() => ScheduleFlush();
private static void ScheduleFlush()
{
if (_flushScheduled) return;
_flushScheduled = true;
EditorApplication.delayCall += Flush;
}
private static void Flush()
{
_flushScheduled = false;
try
{
if (!UnityTcpBridge.IsRunning) return;
JObject payload = BuildSelectionPayload();
if (payload == null) return;
UnityTcpBridge.NotifyAll(EventType, payload);
}
catch (Exception e)
{
try { CodelyLogger.LogError($"[SelectionChangedNotifier] flush failed: {e.Message}"); } catch { }
}
}
private static JObject BuildSelectionPayload() => SelectionPayloadBuilder.Build();
}
}