Compare commits

...

7 Commits

Author SHA1 Message Date
ChocoSwi 26974a5f26 feat: toggle focus 2022-11-05 23:38:03 +09:00
ChocoSwi fa2caf2261 fix: require focus 2022-11-05 23:36:22 +09:00
ChocoSwi 317967423f feat: require focus toggle 2022-11-05 23:29:49 +09:00
ChocoSwi b55dd298ed chore: remove static from RequireFocus 2022-11-05 23:27:35 +09:00
ChocoSwi f13e1e985e feat: show hook started 2022-11-05 23:25:09 +09:00
ChocoSwi ddd65f022e feat: editor inspector 2022-11-05 23:24:33 +09:00
ChocoSwi d53da21bf5 chore: rename _started 2022-11-05 23:22:59 +09:00
6 changed files with 84 additions and 11 deletions

8
Editor.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cff19c4bbf3d41b19e1153313bdf1711
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
{
"name": "SkyHook.Unity.Editor",
"rootNamespace": "SkyHook.Editor",
"references": [
"GUID:5277a9c527b33a210bfa8bb54a667bf4"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e98a4443e126cb545b34b0b136664543
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

27
Editor/SkyHookEditor.cs Normal file
View File

@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace SkyHook.Editor
{
[CustomEditor(typeof(SkyHookManager))]
public class SkyHookEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
SkyHookManager manager = (SkyHookManager)target;
GUI.enabled = false;
EditorGUILayout.Toggle("Hook Started", manager.isHookActive);
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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 31ad107d386d43df9f3f1921ddde6e65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,16 +10,16 @@ namespace SkyHook
{
private static SkyHookManager _instance;
private static bool _isFocused;
public static bool isFocused;
/// <summary>
/// Whether or not the event will be received only if the game window is focused.
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once FieldCanBeMadeReadOnly.Global
public static bool RequireFocus = true;
public bool requireFocus = true;
private bool _started;
public bool isHookActive;
/// <summary>
/// The key updated event data
@ -49,7 +49,7 @@ namespace SkyHook
private void HookCallback(SkyHookEvent ev)
{
if (RequireFocus && !_isFocused)
if (requireFocus && !isFocused)
{
return;
}
@ -64,7 +64,7 @@ namespace SkyHook
new Thread(() =>
{
if (_started) return;
if (isHookActive) return;
var result = SkyHookNative.StartHook(HookCallback);
@ -73,10 +73,10 @@ namespace SkyHook
exception = new SkyHookException(result);
}
_started = true;
isHookActive = true;
started = true;
while (_started)
while (isHookActive)
{
}
}).Start();
@ -93,7 +93,7 @@ namespace SkyHook
private void _StopHook()
{
if (!_started) return;
if (!isHookActive) return;
var result = SkyHookNative.StopHook();
@ -102,7 +102,7 @@ namespace SkyHook
throw new SkyHookException(result);
}
_started = false;
isHookActive = false;
}
public static void StartHook()
@ -122,9 +122,11 @@ namespace SkyHook
private void Update()
{
if (RequireFocus)
if (requireFocus)
{
_isFocused = Application.isFocused;
#if !UNITY_EDITOR
isFocused = Application.isFocused;
#endif
}
}
}