Created
November 10, 2020 03:03
-
-
Save baba-s/b72e597b0c93c871c61e796d984264fc to your computer and use it in GitHub Desktop.
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
using System; | |
using UnityEngine; | |
namespace Kogane | |
{ | |
[AddComponentMenu( "" )] | |
[DisallowMultipleComponent] | |
public sealed class GlobalApplicationEvent : MonoBehaviour | |
{ | |
public static Action<bool> OnPause { get; set; } | |
public static Action<bool> OnFocus { get; set; } | |
public static Action OnQuit { get; set; } | |
private void OnApplicationPause( bool pauseStatus ) | |
{ | |
OnPause?.Invoke( pauseStatus ); | |
} | |
private void OnApplicationFocus( bool hasFocus ) | |
{ | |
OnFocus?.Invoke( hasFocus ); | |
} | |
private void OnApplicationQuit() | |
{ | |
OnQuit?.Invoke(); | |
} | |
[RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.BeforeSceneLoad )] | |
private static void RuntimeInitializeOnLoadMethod() | |
{ | |
if ( FindObjectOfType<GlobalApplicationEvent>() != null ) return; | |
var gameObject = new GameObject( nameof( GlobalApplicationEvent ) ); | |
gameObject.AddComponent<GlobalApplicationEvent>(); | |
//gameObject.hideFlags = HideFlags.HideAndDontSave; | |
DontDestroyOnLoad( gameObject ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment