2022-10-25 17:36:32 +08:00
|
|
|
|
using HybridCLR.Editor;
|
|
|
|
|
using System;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditorInternal;
|
|
|
|
|
|
2023-10-09 15:39:32 +08:00
|
|
|
|
namespace HybridCLR.Editor.Settings
|
2022-10-25 17:36:32 +08:00
|
|
|
|
{
|
2023-10-09 15:39:32 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监听编辑器状态,当编辑器重新 focus 时,重新加载实例,避免某些情景下 svn 、git 等外部修改了数据却无法同步的异常。
|
|
|
|
|
/// </summary>
|
|
|
|
|
[InitializeOnLoad]
|
|
|
|
|
public static class EditorStatusWatcher
|
2022-10-25 17:36:32 +08:00
|
|
|
|
{
|
2023-10-09 15:39:32 +08:00
|
|
|
|
public static Action OnEditorFocused;
|
|
|
|
|
static bool isFocused;
|
|
|
|
|
static EditorStatusWatcher() => EditorApplication.update += Update;
|
|
|
|
|
static void Update()
|
2022-10-25 17:36:32 +08:00
|
|
|
|
{
|
2023-10-09 15:39:32 +08:00
|
|
|
|
if (isFocused != InternalEditorUtility.isApplicationActive)
|
2022-10-25 17:36:32 +08:00
|
|
|
|
{
|
2023-10-09 15:39:32 +08:00
|
|
|
|
isFocused = InternalEditorUtility.isApplicationActive;
|
|
|
|
|
if (isFocused)
|
|
|
|
|
{
|
|
|
|
|
HybridCLRSettings.LoadOrCreate();
|
|
|
|
|
OnEditorFocused?.Invoke();
|
|
|
|
|
}
|
2022-10-25 17:36:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-09 15:39:32 +08:00
|
|
|
|
|
2022-10-25 17:36:32 +08:00
|
|
|
|
}
|