| | 1 | | using DCL.Helpers; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL |
| | 5 | | { |
| | 6 | | public class CursorLockHint : MonoBehaviour |
| | 7 | | { |
| | 8 | | private bool hasBeenShown; |
| | 9 | |
|
| | 10 | | [SerializeField] private ShowHideAnimator toastRoot; |
| | 11 | | [SerializeField] private float duration; |
| | 12 | |
|
| | 13 | | private Coroutine hideRoutine; |
| | 14 | |
|
| | 15 | | private void Start() |
| | 16 | | { |
| 57 | 17 | | Utils.OnCursorLockChanged += HandleCursorLockChanges; |
| 57 | 18 | | } |
| | 19 | |
|
| | 20 | | private void OnDestroy() |
| | 21 | | { |
| 57 | 22 | | Utils.OnCursorLockChanged -= HandleCursorLockChanges; |
| 57 | 23 | | } |
| | 24 | |
|
| | 25 | | private void HandleCursorLockChanges(bool isLocked) |
| | 26 | | { |
| 10 | 27 | | if (!isLocked) |
| | 28 | | { |
| 5 | 29 | | toastRoot.Hide(); |
| 5 | 30 | | return; |
| | 31 | | } |
| 5 | 32 | | if (DataStore.i.camera.panning.Get()) return; |
| 6 | 33 | | if (hasBeenShown) return; |
| 4 | 34 | | if (toastRoot.isVisible) return; |
| 4 | 35 | | toastRoot.gameObject.SetActive(true); |
| 4 | 36 | | toastRoot.Show(); |
| 4 | 37 | | hasBeenShown = true; |
| 4 | 38 | | HideToastAfterDelay(); |
| 4 | 39 | | } |
| | 40 | |
|
| | 41 | | private void HideToastAfterDelay() |
| | 42 | | { |
| 4 | 43 | | if (hideRoutine != null) |
| 0 | 44 | | StopCoroutine(hideRoutine); |
| 4 | 45 | | hideRoutine = StartCoroutine(Utils.Wait(duration, () => |
| | 46 | | { |
| 0 | 47 | | toastRoot.Hide(); |
| 0 | 48 | | hideRoutine = null; |
| 0 | 49 | | })); |
| 4 | 50 | | } |
| | 51 | | } |
| | 52 | | } |