forked from XINCGer/UnityToolchainsTrick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnityFocusUtility.cs
30 lines (28 loc) · 922 Bytes
/
UnityFocusUtility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class UnityFocusUtility
{
public static event Action<bool> OnUnityEditorFocus = (focus) => { };
private static bool _appFocused;
static UnityFocusUtility()
{
EditorApplication.update += Update;
}
private static void Update()
{
if (!_appFocused && UnityEditorInternal.InternalEditorUtility.isApplicationActive)
{
_appFocused = UnityEditorInternal.InternalEditorUtility.isApplicationActive;
OnUnityEditorFocus(true);
Debug.Log("On focus window!");
}
else if (_appFocused && !UnityEditorInternal.InternalEditorUtility.isApplicationActive)
{
_appFocused = UnityEditorInternal.InternalEditorUtility.isApplicationActive;
OnUnityEditorFocus(false);
Debug.Log("On lost focus");
}
}
}