| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.Audio; |
| | 3 | |
|
| | 4 | | public class HUDAudioHandler : MonoBehaviour |
| | 5 | | { |
| 0 | 6 | | public static HUDAudioHandler i { get; private set; } |
| | 7 | |
|
| | 8 | | [SerializeField] |
| | 9 | | AudioMixer audioMixer; |
| | 10 | | [SerializeField] |
| | 11 | | AudioMixerSnapshot snapshotInWorld, snapshotOutOfWorld; |
| | 12 | |
|
| | 13 | | [HideInInspector] |
| | 14 | | public ulong chatLastCheckedTimestamp; |
| | 15 | |
|
| | 16 | | private void Awake() |
| | 17 | | { |
| 51 | 18 | | if (i != null) |
| | 19 | | { |
| 0 | 20 | | Destroy(this); |
| 0 | 21 | | return; |
| | 22 | | } |
| | 23 | |
|
| 51 | 24 | | i = this; |
| | 25 | |
|
| 51 | 26 | | RefreshChatLastCheckedTimestamp(); |
| 51 | 27 | | CommonScriptableObjects.rendererState.OnChange += OnRendererStateChange; |
| 51 | 28 | | CommonScriptableObjects.allUIHidden.OnChange += OnAllUIHiddenChange; |
| 51 | 29 | | } |
| | 30 | |
|
| | 31 | | private void OnDestroy() |
| | 32 | | { |
| 51 | 33 | | CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChange; |
| 51 | 34 | | CommonScriptableObjects.allUIHidden.OnChange -= OnAllUIHiddenChange; |
| 51 | 35 | | } |
| | 36 | |
|
| | 37 | | public void RefreshChatLastCheckedTimestamp() |
| | 38 | | { |
| | 39 | | // Get UTC datetime (used to determine whether chat messages are old or new) |
| 51 | 40 | | chatLastCheckedTimestamp = (ulong)(System.DateTime.UtcNow.Subtract(new System.DateTime(1970, 1, 1))).TotalMillis |
| 51 | 41 | | } |
| | 42 | |
|
| | 43 | | void OnRendererStateChange(bool isReady, bool isReadyPrevious) |
| | 44 | | { |
| 0 | 45 | | if (isReady) |
| 0 | 46 | | snapshotInWorld.TransitionTo(0.1f); |
| | 47 | | else |
| 0 | 48 | | snapshotOutOfWorld.TransitionTo(0.2f); |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | void OnAllUIHiddenChange(bool current, bool previous) |
| | 52 | | { |
| 2 | 53 | | if (current) |
| 1 | 54 | | AudioScriptableObjects.UIHide.Play(true); |
| | 55 | | else |
| 1 | 56 | | AudioScriptableObjects.UIShow.Play(true); |
| 1 | 57 | | } |
| | 58 | | } |