-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Keep Selection
- Loading branch information
Showing
6 changed files
with
166 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using AOT; | ||
using System.Runtime.InteropServices; // for DllImport | ||
using UnityEngine; | ||
|
||
namespace WebGLSupport | ||
{ | ||
static class WebGLWindowPlugin | ||
{ | ||
#if UNITY_WEBGL && !UNITY_EDITOR | ||
[DllImport("__Internal")] | ||
public static extern void WebGLWindowOnFocus(Action cb); | ||
|
||
[DllImport("__Internal")] | ||
public static extern void WebGLWindowOnBlur(Action cb); | ||
|
||
#else | ||
public static void WebGLWindowOnFocus(Action cb) { } | ||
public static void WebGLWindowOnBlur(Action cb) { } | ||
#endif | ||
|
||
} | ||
|
||
public static class WebGLWindow | ||
{ | ||
public static bool Focus { get; private set; } | ||
public static event Action OnFocusEvent = () => { }; | ||
public static event Action OnBlurEvent = () => { }; | ||
|
||
static void Init() | ||
{ | ||
Focus = true; | ||
WebGLWindowPlugin.WebGLWindowOnFocus(OnWindowFocus); | ||
WebGLWindowPlugin.WebGLWindowOnBlur(OnWindowBlur); | ||
} | ||
|
||
[MonoPInvokeCallback(typeof(Action))] | ||
static void OnWindowFocus() | ||
{ | ||
Focus = true; | ||
OnFocusEvent(); | ||
} | ||
|
||
[MonoPInvokeCallback(typeof(Action))] | ||
static void OnWindowBlur() | ||
{ | ||
Focus = false; | ||
OnBlurEvent(); | ||
} | ||
|
||
[RuntimeInitializeOnLoadMethod] | ||
static void RuntimeInitializeOnLoadMethod() | ||
{ | ||
Init(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var WebGLWindow = { | ||
WebGLWindowOnFocus: function (cb) { | ||
window.addEventListener('focus', function () { | ||
Runtime.dynCall("v", cb, []); | ||
}); | ||
}, | ||
WebGLWindowOnBlur: function (cb) { | ||
window.addEventListener('blur', function () { | ||
Runtime.dynCall("v", cb, []); | ||
}); | ||
}, | ||
} | ||
|
||
mergeInto(LibraryManager.library, WebGLWindow); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.