| | 1 | | using System.Collections; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.Tutorial |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Class that represents the onboarding tutorial step related to how to open the controls panel. |
| | 8 | | /// </summary> |
| | 9 | | public class TutorialStep_OpenControlsPanel : TutorialStep |
| | 10 | | { |
| | 11 | | [SerializeField] AudioEvent audioEventSuccess; |
| | 12 | | [SerializeField] private InputAction_Trigger toggleControlsHud; |
| | 13 | |
|
| | 14 | | private bool controlsHasBeenOpened = false; |
| | 15 | | private bool controlsHasBeenClosed = false; |
| | 16 | | private BooleanVariable originalControlsTriggerIsBlocked; |
| | 17 | |
|
| | 18 | | public override void OnStepStart() |
| | 19 | | { |
| 1 | 20 | | base.OnStepStart(); |
| | 21 | |
|
| 1 | 22 | | originalControlsTriggerIsBlocked = toggleControlsHud.isTriggerBlocked; |
| 1 | 23 | | if (toggleControlsHud != null) |
| 1 | 24 | | toggleControlsHud.isTriggerBlocked = null; |
| | 25 | |
|
| 1 | 26 | | if (tutorialController != null && |
| | 27 | | tutorialController.hudController != null && |
| | 28 | | tutorialController.hudController.controlsHud != null) |
| | 29 | | { |
| 0 | 30 | | tutorialController.hudController.controlsHud.OnControlsOpened += ControlsHud_OnControlsOpened; |
| 0 | 31 | | tutorialController.hudController.controlsHud.OnControlsClosed += ControlsHud_OnControlsClosed; |
| | 32 | | } |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | public override IEnumerator OnStepExecute() |
| | 36 | | { |
| 4 | 37 | | yield return new WaitUntil(() => controlsHasBeenOpened && controlsHasBeenClosed); |
| 1 | 38 | | audioEventSuccess.Play(true); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void OnStepFinished() |
| | 42 | | { |
| 1 | 43 | | base.OnStepFinished(); |
| | 44 | |
|
| 1 | 45 | | if (tutorialController != null && |
| | 46 | | tutorialController.hudController != null && |
| | 47 | | tutorialController.hudController.controlsHud != null) |
| | 48 | | { |
| 0 | 49 | | tutorialController.hudController.controlsHud.OnControlsOpened -= ControlsHud_OnControlsOpened; |
| 0 | 50 | | tutorialController.hudController.controlsHud.OnControlsClosed -= ControlsHud_OnControlsClosed; |
| | 51 | | } |
| | 52 | |
|
| 1 | 53 | | if (toggleControlsHud != null) |
| 1 | 54 | | toggleControlsHud.isTriggerBlocked = originalControlsTriggerIsBlocked; |
| 1 | 55 | | } |
| | 56 | |
|
| | 57 | | internal void ControlsHud_OnControlsOpened() |
| | 58 | | { |
| 1 | 59 | | if (!controlsHasBeenOpened && mainSection.activeSelf) |
| 1 | 60 | | controlsHasBeenOpened = true; |
| | 61 | |
|
| 1 | 62 | | tutorialController?.hudController?.taskbarHud?.SetVisibility(true); |
| 1 | 63 | | CommonScriptableObjects.featureKeyTriggersBlocked.Set(false); |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | internal void ControlsHud_OnControlsClosed() |
| | 67 | | { |
| 1 | 68 | | if (controlsHasBeenOpened && mainSection.activeSelf) |
| 1 | 69 | | controlsHasBeenClosed = true; |
| 1 | 70 | | } |
| | 71 | | } |
| | 72 | | } |