PlaytestingCanvas.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace Agava.WebUtility.Samples
  4. {
  5. public class PlaytestingCanvas : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private Text _adBlockStatusText;
  9. private void OnEnable()
  10. {
  11. WebApplication.InBackgroundChangeEvent += OnInBackgroundChange;
  12. }
  13. private void OnDisable()
  14. {
  15. WebApplication.InBackgroundChangeEvent -= OnInBackgroundChange;
  16. }
  17. private void Update()
  18. {
  19. _adBlockStatusText.color = AdBlock.Enabled ? Color.red : Color.green;
  20. _adBlockStatusText.text = $"{nameof(AdBlock)}.{nameof(AdBlock.Enabled)} = {AdBlock.Enabled}";
  21. }
  22. private void OnInBackgroundChange(bool inBackground)
  23. {
  24. // Use both pause and volume muting methods at the same time.
  25. // They're both broken in Web, but work perfect together. Trust me on this.
  26. AudioListener.pause = inBackground;
  27. AudioListener.volume = inBackground ? 0f : 1f;
  28. }
  29. }
  30. }