< Summary

Class:DCL.Tutorial.TutorialStep
Assembly:Onboarding
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Tutorial/Scripts/TutorialStep.cs
Covered lines:2
Uncovered lines:52
Coverable lines:54
Total lines:157
Line coverage:3.7% (2 of 54)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TutorialStep()0%110100%
TutorialStep()0%110100%
OnStepStart()0%1321100%
OnStepExecute()0%6200%
OnStepPlayHideAnimation()0%56700%
OnStepFinished()0%30500%
OnShowAnimationFinish()0%6200%
OnHideAnimationFinish()0%2100%
PlayAndWaitForHideAnimation()0%20400%
ConfigureSkipOptions()0%30500%
YesSkipInputAction_OnFinished(...)0%6200%
NoSkipInputAction_OnFinished(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Tutorial/Scripts/TutorialStep.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using UnityEngine;
 4
 5namespace DCL.Tutorial
 6{
 7    /// <summary>
 8    /// Class that represents one of the steps included in the onboarding tutorial.
 9    /// </summary>
 10    public class TutorialStep : MonoBehaviour
 11    {
 112        protected static int STEP_FINISHED_ANIMATOR_TRIGGER = Animator.StringToHash("StepFinished");
 13
 14        internal event Action OnShowAnimationFinished;
 15        internal event Action OnJustAfterStepExecuted;
 16
 17        [SerializeField] internal bool unlockCursorAtStart = false;
 18        [SerializeField] internal bool show3DTeacherAtStart = false;
 19        [SerializeField] internal protected RectTransform teacherPositionRef;
 20        [SerializeField] internal GameObject mainSection;
 21        [SerializeField] internal GameObject skipTutorialSection;
 22        [SerializeField] internal InputAction_Hold yesSkipInputAction;
 23        [SerializeField] internal InputAction_Hold noSkipInputAction;
 24
 25        protected TutorialController tutorialController;
 26        protected Animator stepAnimator;
 27        protected MouseCatcher mouseCatcher;
 28        protected bool hideAnimationFinished = false;
 29        protected bool blockSkipActions = false;
 30
 5931        internal bool letInstantiation = true;
 32
 33        /// <summary>
 34        /// Step initialization (occurs before OnStepExecute() execution).
 35        /// </summary>
 36        public virtual void OnStepStart()
 37        {
 038            tutorialController = TutorialController.i;
 039            stepAnimator = GetComponent<Animator>();
 40
 041            mouseCatcher = InitialSceneReferences.i?.mouseCatcher;
 42
 043            if (unlockCursorAtStart)
 044                mouseCatcher?.UnlockCursor();
 45
 046            if (tutorialController != null)
 47            {
 048                tutorialController.ShowTeacher3DModel(show3DTeacherAtStart);
 49
 050                if (tutorialController.teacher != null)
 51                {
 052                    if (tutorialController.currentStepIndex > 0)
 053                        tutorialController.teacher.PlaySpeakSound();
 54                    else
 055                        tutorialController.teacher.PlayHappySound(1f);
 56                }
 57
 058                if (show3DTeacherAtStart && teacherPositionRef != null)
 59                {
 060                    tutorialController.SetTeacherPosition(teacherPositionRef.position);
 61
 062                    if (tutorialController.teacher.isHiddenByAnAnimation)
 063                        tutorialController.teacher.PlayAnimation(TutorialTeacher.TeacherAnimation.Reset);
 64                }
 65            }
 66
 067            ConfigureSkipOptions();
 068        }
 69
 70        /// <summary>
 71        /// Executes the main flow of the step and waits for its finalization.
 72        /// </summary>
 73        /// <returns></returns>
 074        public virtual IEnumerator OnStepExecute() { yield break; }
 75
 76        /// <summary>
 77        /// Executes the final animation and waits for its finalization and for any camera blending.
 78        /// </summary>
 79        /// <returns></returns>
 80        public virtual IEnumerator OnStepPlayHideAnimation()
 81        {
 082            blockSkipActions = true;
 083            OnJustAfterStepExecuted?.Invoke();
 084            yield return PlayAndWaitForHideAnimation();
 085            yield return null;
 086            yield return new WaitUntil(() => !CommonScriptableObjects.cameraIsBlending.Get());
 087        }
 88
 89        /// <summary>
 90        /// Step finalization (occurs after OnStepExecute() execution).
 91        /// </summary>
 92        public virtual void OnStepFinished()
 93        {
 094            if (mainSection != null &&
 95                skipTutorialSection != null &&
 96                yesSkipInputAction != null &&
 97                noSkipInputAction)
 98            {
 099                yesSkipInputAction.OnFinished -= YesSkipInputAction_OnFinished;
 0100                noSkipInputAction.OnFinished -= NoSkipInputAction_OnFinished;
 101            }
 0102        }
 103
 0104        private void OnShowAnimationFinish() { OnShowAnimationFinished?.Invoke(); }
 105
 106        /// <summary>
 107        /// Warn about the finalization of the hide animation of the step
 108        /// </summary>
 0109        private void OnHideAnimationFinish() { hideAnimationFinished = true; }
 110
 111        private IEnumerator PlayAndWaitForHideAnimation()
 112        {
 0113            if (stepAnimator == null)
 0114                yield break;
 115
 0116            stepAnimator.SetTrigger(STEP_FINISHED_ANIMATOR_TRIGGER);
 0117            yield return new WaitUntil(() => hideAnimationFinished);
 0118        }
 119
 120        private void ConfigureSkipOptions()
 121        {
 0122            if (mainSection != null &&
 123                skipTutorialSection != null &&
 124                yesSkipInputAction != null &&
 125                noSkipInputAction)
 126            {
 0127                yesSkipInputAction.OnFinished += YesSkipInputAction_OnFinished;
 0128                noSkipInputAction.OnFinished += NoSkipInputAction_OnFinished;
 129            }
 0130        }
 131
 132        private void YesSkipInputAction_OnFinished(DCLAction_Hold action)
 133        {
 0134            if (skipTutorialSection.activeSelf)
 135            {
 0136                tutorialController.SkipTutorial();
 137            }
 0138        }
 139
 140        private void NoSkipInputAction_OnFinished(DCLAction_Hold action)
 141        {
 0142            if (blockSkipActions)
 0143                return;
 144
 0145            if (mainSection.activeSelf)
 146            {
 0147                mainSection.SetActive(false);
 0148                skipTutorialSection.SetActive(true);
 0149            }
 0150            else if (skipTutorialSection.activeSelf)
 151            {
 0152                mainSection.SetActive(true);
 0153                skipTutorialSection.SetActive(false);
 154            }
 0155        }
 156    }
 157}