From 26974a5f263027590a3dfda9056363f59665da96 Mon Sep 17 00:00:00 2001 From: ChocoSwi Date: Sat, 5 Nov 2022 23:38:03 +0900 Subject: [PATCH] feat: toggle focus --- Editor/SkyHookEditor.cs | 5 +++++ Runtime/SkyHookManager.cs | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Editor/SkyHookEditor.cs b/Editor/SkyHookEditor.cs index 774c54f..f725bf9 100644 --- a/Editor/SkyHookEditor.cs +++ b/Editor/SkyHookEditor.cs @@ -17,6 +17,11 @@ namespace SkyHook.Editor GUI.enabled = true; manager.requireFocus = EditorGUILayout.Toggle("Require Focus", manager.requireFocus); + + GUI.enabled = manager.requireFocus; + SkyHookManager.isFocused = EditorGUILayout.Toggle("Focus", SkyHookManager.isFocused); + GUI.enabled = true; + } } } diff --git a/Runtime/SkyHookManager.cs b/Runtime/SkyHookManager.cs index 63d29b9..49371ff 100644 --- a/Runtime/SkyHookManager.cs +++ b/Runtime/SkyHookManager.cs @@ -10,7 +10,7 @@ namespace SkyHook { private static SkyHookManager _instance; - private static bool _isFocused; + public static bool isFocused; /// /// Whether or not the event will be received only if the game window is focused. @@ -49,7 +49,7 @@ namespace SkyHook private void HookCallback(SkyHookEvent ev) { - if (requireFocus && !_isFocused) + if (requireFocus && !isFocused) { return; } @@ -124,7 +124,9 @@ namespace SkyHook { if (requireFocus) { - _isFocused = Application.isFocused; + #if !UNITY_EDITOR + isFocused = Application.isFocused; + #endif } } }