Last active
August 26, 2023 14:27
-
-
Save ErnSur/ad2714817999daa97f86aef53367de39 to your computer and use it in GitHub Desktop.
Event system for uGUI singletons
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
public class FallbackEventSystem : MonoBehaviour | |
{ | |
private GameObject _fallbackEventSystem; | |
private void Awake() | |
{ | |
CreateFallbackEventSystem(); | |
} | |
private void OnEnable() | |
{ | |
// If Event System doesn't exist in the scene | |
// Activate the fallback event system | |
_fallbackEventSystem.SetActive(EventSystem.current == null); | |
} | |
private void OnDisable() | |
{ | |
_fallbackEventSystem.SetActive(false); | |
} | |
private void CreateFallbackEventSystem() | |
{ | |
_fallbackEventSystem = | |
new GameObject("Fallback Event System", typeof(EventSystem), typeof(StandaloneInputModule)); | |
_fallbackEventSystem.transform.SetParent(transform); | |
_fallbackEventSystem.SetActive(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment