Last active
October 12, 2022 17:07
-
-
Save kurtdekker/501489d3ea837ec245cb89f6369c70d9 to your computer and use it in GitHub Desktop.
Overlay input-blocking facility for Unity3D (input / click blocker / inhibitor)
This file contains hidden or 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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// @kurtdekker | |
// | |
// Purpose: | |
// - to inhibit processing of input whenever a popup is enabled | |
// | |
// To use: | |
// - place one of these somewhere in any and all popup windows you make | |
// | |
// - in code, query OverlayBlocker.ShouldAllowInput to decide if you need to process clicks | |
// | |
public class OverlayBlocker : MonoBehaviour | |
{ | |
public static bool ShouldAllowInput | |
{ | |
get | |
{ | |
return counter == 0; | |
} | |
} | |
static int counter; | |
void OnEnable() | |
{ | |
counter++; | |
} | |
void OnDisable() | |
{ | |
counter--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment