< Summary

Class:DCL.Tutorial.TutorialStep
Assembly:Onboarding
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Tutorial/Scripts/TutorialStep.cs
Covered lines:46
Uncovered lines:8
Coverable lines:54
Total lines:158
Line coverage:85.1% (46 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%13.8812076.47%
OnStepExecute()0%6200%
OnStepPlayHideAnimation()0%770100%
OnStepFinished()0%550100%
OnShowAnimationFinish()0%2.52050%
OnHideAnimationFinish()0%2100%
PlayAndWaitForHideAnimation()0%440100%
ConfigureSkipOptions()0%550100%
YesSkipInputAction_OnFinished(...)0%2.152066.67%
NoSkipInputAction_OnFinished(...)0%4.024090%

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        internal Animator stepAnimator;
 27        internal MouseCatcher mouseCatcher;
 28        protected bool hideAnimationFinished = false;
 29        internal bool blockSkipActions = false;
 30
 9831        internal bool letInstantiation = true;
 32
 33        /// <summary>
 34        /// Step initialization (occurs before OnStepExecute() execution).
 35        /// </summary>
 36        public virtual void OnStepStart()
 37        {
 1538            tutorialController = TutorialController.i;
 1539            stepAnimator = GetComponent<Animator>();
 40
 1541            mouseCatcher = SceneReferences.i?.mouseCatcher;
 42
 1543            if (unlockCursorAtStart)
 1044                mouseCatcher?.UnlockCursor();
 45
 1546            if (tutorialController != null)
 47            {
 1548                tutorialController.ShowTeacher3DModel(show3DTeacherAtStart);
 49
 1550                if (tutorialController.configuration.teacher != null)
 51                {
 052                    if (tutorialController.currentStepIndex > 0)
 053                        tutorialController.configuration.teacher.PlaySpeakSound();
 54                    else
 055                        tutorialController.configuration.teacher.PlayHappySound(1f);
 56                }
 57
 1558                if (show3DTeacherAtStart && teacherPositionRef != null)
 59                {
 1560                    tutorialController.SetTeacherPosition(teacherPositionRef.position);
 61
 1562                    if (tutorialController.configuration.teacher != null &&
 63                        tutorialController.configuration.teacher.isHiddenByAnAnimation)
 064                        tutorialController.configuration.teacher.PlayAnimation(TutorialTeacher.TeacherAnimation.Reset);
 65                }
 66            }
 67
 1568            ConfigureSkipOptions();
 1569        }
 70
 71        /// <summary>
 72        /// Executes the main flow of the step and waits for its finalization.
 73        /// </summary>
 74        /// <returns></returns>
 075        public virtual IEnumerator OnStepExecute() { yield break; }
 76
 77        /// <summary>
 78        /// Executes the final animation and waits for its finalization and for any camera blending.
 79        /// </summary>
 80        /// <returns></returns>
 81        public virtual IEnumerator OnStepPlayHideAnimation()
 82        {
 1583            blockSkipActions = true;
 1584            OnJustAfterStepExecuted?.Invoke();
 1585            yield return PlayAndWaitForHideAnimation();
 1586            yield return null;
 3087            yield return new WaitUntil(() => !CommonScriptableObjects.cameraIsBlending.Get());
 1588        }
 89
 90        /// <summary>
 91        /// Step finalization (occurs after OnStepExecute() execution).
 92        /// </summary>
 93        public virtual void OnStepFinished()
 94        {
 2595            if (mainSection != null &&
 96                skipTutorialSection != null &&
 97                yesSkipInputAction != null &&
 98                noSkipInputAction)
 99            {
 5100                yesSkipInputAction.OnFinished -= YesSkipInputAction_OnFinished;
 5101                noSkipInputAction.OnFinished -= NoSkipInputAction_OnFinished;
 102            }
 25103        }
 104
 1105        internal void OnShowAnimationFinish() { OnShowAnimationFinished?.Invoke(); }
 106
 107        /// <summary>
 108        /// Warn about the finalization of the hide animation of the step
 109        /// </summary>
 0110        internal void OnHideAnimationFinish() { hideAnimationFinished = true; }
 111
 112        private IEnumerator PlayAndWaitForHideAnimation()
 113        {
 15114            if (stepAnimator == null)
 14115                yield break;
 116
 1117            stepAnimator.SetTrigger(STEP_FINISHED_ANIMATOR_TRIGGER);
 3118            yield return new WaitUntil(() => hideAnimationFinished);
 1119        }
 120
 121        private void ConfigureSkipOptions()
 122        {
 15123            if (mainSection != null &&
 124                skipTutorialSection != null &&
 125                yesSkipInputAction != null &&
 126                noSkipInputAction)
 127            {
 5128                yesSkipInputAction.OnFinished += YesSkipInputAction_OnFinished;
 5129                noSkipInputAction.OnFinished += NoSkipInputAction_OnFinished;
 130            }
 15131        }
 132
 133        private void YesSkipInputAction_OnFinished(DCLAction_Hold action)
 134        {
 1135            if (skipTutorialSection.activeSelf)
 136            {
 0137                tutorialController.SkipTutorial();
 138            }
 1139        }
 140
 141        internal void NoSkipInputAction_OnFinished(DCLAction_Hold action)
 142        {
 2143            if (blockSkipActions)
 0144                return;
 145
 2146            if (mainSection.activeSelf)
 147            {
 1148                mainSection.SetActive(false);
 1149                skipTutorialSection.SetActive(true);
 1150            }
 1151            else if (skipTutorialSection.activeSelf)
 152            {
 1153                mainSection.SetActive(true);
 1154                skipTutorialSection.SetActive(false);
 155            }
 1156        }
 157    }
 158}