1234567891011121314151617181920212223242526272829303132333435 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace Agava.WebUtility.Samples
- {
- public class PlaytestingCanvas : MonoBehaviour
- {
- [SerializeField]
- private Text _adBlockStatusText;
- private void OnEnable()
- {
- WebApplication.InBackgroundChangeEvent += OnInBackgroundChange;
- }
- private void OnDisable()
- {
- WebApplication.InBackgroundChangeEvent -= OnInBackgroundChange;
- }
- private void Update()
- {
- _adBlockStatusText.color = AdBlock.Enabled ? Color.red : Color.green;
- _adBlockStatusText.text = $"{nameof(AdBlock)}.{nameof(AdBlock.Enabled)} = {AdBlock.Enabled}";
- }
- private void OnInBackgroundChange(bool inBackground)
- {
- // Use both pause and volume muting methods at the same time.
- // They're both broken in Web, but work perfect together. Trust me on this.
- AudioListener.pause = inBackground;
- AudioListener.volume = inBackground ? 0f : 1f;
- }
- }
- }
|