private IEnumerator TutorialClicks()
        {
            idleTime     = 0;
            clickEnabled = false;
            yield return(TimeEngine.Wait(0.4f));

            TutorialUI.Click(TutorialHelper.GetWorldPosition());
            yield return(TimeEngine.Wait(0.1f));

            AssessmentConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.UIPopup);
            yield return(TimeEngine.Wait(0.2f));

            clickEnabled = true;
        }
Esempio n. 2
0
        private IEnumerator PlaceCoroutine()
        {
            List <Vector3> positions = new List <Vector3>();
            WorldBounds    bounds    = WorldBounds.Instance;
            float          xMin      = bounds.ToTheLeftQuestionStart().x;
            float          xMax      = bounds.ToTheRightQuestionStart().x;
            float          yMin      = bounds.YMin();
            float          yMax      = bounds.YMax();
            float          z         = bounds.DefaultZ();

            if (AppConstants.VerboseLogging)
            {
                Debug.Log("xMin" + xMin);
                Debug.Log("xMax" + xMax);
                Debug.Log("yMin" + yMin);
                Debug.Log("yMax" + yMax);
            }

            for (float x = xMin; x < xMax; x += 4.3f)
            {
                for (float y = yMin; y < yMax; y += 1.7f)
                {
                    float dx  = Random.Range(-0.2f, 0.2f);
                    float dy  = Random.Range(-0.1f, 0.2f);
                    var   vec = new Vector3(x + dx, y + dy, z);
                    positions.Add(vec);
                    if (AppConstants.VerboseLogging)
                    {
                        Debug.Log("VECTOR" + vec);
                    }
                }
            }

            if (AppConstants.VerboseLogging)
            {
                Debug.Log("COUNT:" + positions.Count);
            }
            positions = positions.Shuffle();

            foreach (var a in allAnswers)
            {
                yield return(PlaceAnswer(a, positions));
            }

            yield return(TimeEngine.Wait(0.65f));

            isAnimating = false;
        }
        private IEnumerator AnimationCoroutine(Action callback)
        {
            var particles =
                Instantiate(poof, AnturaPosition.position, AnturaPosition.rotation)
                as GameObject;

            var particles2 =
                Instantiate(poof, AnturaPosition.position, AnturaPosition.rotation)
                as GameObject;

            particles2.transform.localScale = new Vector3(2, 2, 2);
            particles2.SetLayerRecursive(AnturaLayers.ModelsOverUI);
            particles.transform.localScale = new Vector3(2, 2, 2);
            particles.SetLayerRecursive(AnturaLayers.ModelsOverUI);

            AssessmentConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.Poof);

            yield return(TimeEngine.Wait(0.15f));

            AnturaAnimationController antura =
                Instantiate(anturaPrefab, AnturaPosition.position, AnturaPosition.rotation)
                as AnturaAnimationController;

            antura.gameObject.AddComponent <BringAnturaInFlagSpace>();

            antura.transform.localScale = Vector3.zero;
            antura.transform.DOScale(Vector3.one, 0.2f);

            yield return(TimeEngine.Wait(0.9f));

            antura.DoShout(
                () => AssessmentConfiguration.Instance.Context.GetAudioManager()
                .PlaySound(Sfx.DogBarking)
                );

            yield return(TimeEngine.Wait(1.2f));

            particles2 =
                Instantiate(poof, AnturaPosition.position, AnturaPosition.rotation)
                as GameObject;

            particles2.transform.localScale = new Vector3(2, 2, 2);
            particles2.SetLayerRecursive(AnturaLayers.ModelsOverUI);
            yield return(TimeEngine.Wait(1f));

            antura.transform.DOScale(Vector3.zero, 0.2f).SetEase(Ease.InExpo);
            callback();
        }
Esempio n. 4
0
        private IEnumerator PlaceCoroutine()
        {
            var bounds = WorldBounds.Instance;

            // Text justification "algorithm"
            var   gap            = bounds.QuestionGap();
            float letterGap      = 1.3f;
            float occupiedSpace  = allAnswers.Length * (letterGap * letterSize);
            float spaceIncrement = (letterGap * letterSize);

            var     flow = AssessmentConfiguration.Instance.LocaleTextFlow;
            float   sign;
            Vector3 currentPos = Vector3.zero;

            currentPos.y = -1;
            currentPos.z = bounds.DefaultZ();

            if (flow == AssessmentConfiguration.TextFlow.RightToLeft)
            {
                currentPos.x = occupiedSpace / 2f;
                sign         = -1;
            }
            else
            {
                currentPos.x = -occupiedSpace / 2f;
                sign         = 1;
            }

            currentPos.y -= 1.5f;

            foreach (var a in allAnswers)
            {
                yield return(PlaceAnswer(a, currentPos));

                currentPos.x += spaceIncrement * sign;
            }

            yield return(TimeEngine.Wait(0.65f));

            isAnimating = false;
        }
        IEnumerator RemoveCoroutine()
        {
            foreach (var q in allQuestions)
            {
                foreach (var p in q.GetPlaceholders())
                {
                    yield return(FadeOutPlaceholder(p));
                }

                foreach (var img in images)
                {
                    yield return(FadeOutImage(img));
                }

                yield return(FadeOutQuestion(q));
            }

            // give time to finish animating elements
            yield return(TimeEngine.Wait(0.65f));

            isAnimating = false;
        }
        private IEnumerator CheckCoroutine(List <PlaceholderBehaviour> placeholders,
                                           List <IQuestion> questions,
                                           IDragManager dragManager)
        {
            dragManager.DisableInput();

            bool areAllCorrect = AreQuestionsCorrect(questions);

            if (areAllCorrect)
            {
                // Just trigger OnQuestionAnswered events if all are correct
                foreach (var q in questions)
                {
                    var behaviour = q.gameObject.GetComponent <QuestionBehaviour>();
                    behaviour.OnQuestionAnswered();
                    AssessmentConfiguration.Instance.Context.GetLogManager().OnAnswer(q.LetterData(), true);

                    yield return(TimeEngine.Wait(behaviour.TimeToWait()));
                }
            }
            else
            {
                foreach (var p in placeholders)
                {
                    if (p.LinkedDroppable != null)
                    {
                        var set  = p.Placeholder.GetQuestion().GetAnswerSet();
                        var answ = p.LinkedDroppable.GetAnswer();
                        if (set.IsCorrect(answ) == false)
                        {
                            AssessmentConfiguration.Instance.Context.GetLogManager().OnAnswer(answ.Data(), false);
                            p.LinkedDroppable.Detach(true);
                        }
                    }
                }
            }

            allCorrect = areAllCorrect;

            while (wrongAnswerAnimationPlaying)
            {
                yield return(null); // wait only if previous message has not finished
            }
            if (allCorrect)
            {
                if (AppConstants.VerboseLogging)
                {
                    Debug.Log("CheckCoroutine CORRECT");
                }

                audioManager.PlaySound(Sfx.StampOK);
                yield return(TimeEngine.Wait(0.4f));

                checkmarkWidget.Show(true);
                yield return(TimeEngine.Wait(1.0f));
            }
            else
            {
                if (AppConstants.VerboseLogging)
                {
                    Debug.Log("CheckCoroutine WRONG");
                }

                wrongAnswerAnimationPlaying = true;
                Coroutine.Start(WrongAnswerCoroutine());
            }

            coroutineEnded = true;
            dragManager.EnableInput();
        }
 void Start()
 {
     TimeEngine.AddTickable(this);
 }
        IEnumerator CheckStateAndSetAnimation()
        {
            antura.State = AnturaAnimationStates.walking;

            yield return(TimeEngine.Wait(1.0f));

            yield return(transform
                         .DOMove(anturaCenter.position, 3.0f)
                         .SetEase(Ease.InOutSine));

            yield return(TimeEngine.Wait(2.6f));

            sleepingParticles = Instantiate(sleepingParticles, paritclesPos) as ParticleSystem;
            sleepingParticles.transform.localPosition = Vector3.zero;
            antura.State = AnturaAnimationStates.sleeping;
            yield return(TimeEngine.Wait(2.1f));

            playPushAnturaSound();
            yield return(TimeEngine.Wait(1.0f));

            Coroutine.Start(TutorialClicks());

            idleTime = 0;
            while (currentState < 3)
            {
                while (stateDelta == 0)
                {
                    if (idleTime > 3f)
                    {
                        Coroutine.Start(TutorialClicks());
                        idleTime = 0;
                    }

                    yield return(null);
                }


                if (stateDelta > 0)
                {
                    IncreaseState();
                }

                if (stateDelta < 0)
                {
                    DecreaseState();
                }

                var emission = sleepingParticles.emission;


                switch (currentState)
                {
                case 0:
                    Coroutine.Start(TutorialClicks());
                    emission.enabled = true;
                    antura.State     = AnturaAnimationStates.sleeping;
                    yield return(TimeEngine.Wait(0.3f));

                    PlayStateSound();
                    TurnAntura(-75f);
                    yield return(TimeEngine.Wait(0.3f));

                    soundPlayed = false;
                    break;

                case 1:
                    Coroutine.Start(TutorialClicks());
                    emission.enabled = false;
                    antura.State     = AnturaAnimationStates.sitting;
                    yield return(TimeEngine.Wait(0.8f));

                    PlayStateSound();
                    yield return(TimeEngine.Wait(1.0f));

                    soundPlayed = false;
                    break;

                case 2:
                    Coroutine.Start(TutorialClicks());
                    antura.DoShout(() => audioManager.PlaySound(Sfx.DogBarking));
                    PlayStateSound();
                    yield return(TimeEngine.Wait(1.5f));

                    soundPlayed = false;
                    break;

                case 3:
                    audioManager.PlaySound(Sfx.Win);
                    antura.DoCharge(() => StartMoving());
                    TurnAntura(-65f);
                    soundPlayed = false;
                    break;

                default:
                    break;
                }

                currentTreshold = currentMaxTreshold * 0.99f;
                stateDelta      = 0;
            }

            yield return(TimeEngine.Wait(1.0f));
        }
 void OnDestroy()
 {
     TimeEngine.RemoveTickable(this);
 }
        public override IEnumerator GetPlaceCoroutine()
        {
            // Count questions and answers
            int questionsNumber    = 0;
            int placeHoldersNumber = 0;

            foreach (var q in allQuestions)
            {
                questionsNumber++;
                placeHoldersNumber += q.PlaceholdersCount();
            }

            var bounds = WorldBounds.Instance;

            // Text justification "algorithm"
            var gap = bounds.QuestionGap();

            float occupiedSpace = answerSize * placeHoldersNumber; //Different from default placer
            float blankSpace    = gap - occupiedSpace;

            float spaceIncrement = blankSpace / (questionsNumber + 1);

            var     flow = AssessmentConfiguration.Instance.LocaleTextFlow;
            float   sign;
            Vector3 currentPos;

            if (flow == AssessmentConfiguration.TextFlow.RightToLeft)
            {
                currentPos = bounds.ToTheRightQuestionStart();
                //currentPos.x -= answerSize / 2.0f;
                sign = -1;
            }
            else
            {
                currentPos    = bounds.ToTheLeftQuestionStart();
                currentPos.x += answerSize / 2.0f;
                sign          = 1;
            }

            currentPos.y -= bounds.LetterSize() * 1.35f;

            int questionIndex = 0;

            for (int i = 0; i < questionsNumber; i++)
            {
                currentPos.x += spaceIncrement * sign;
                float min = 1000, max = -1000;

                foreach (var p in allQuestions[questionIndex].GetPlaceholders())
                {
                    currentPos.x += (answerSize * sign) / 2;

                    if (currentPos.x > max)
                    {
                        max = currentPos.x;
                    }

                    if (currentPos.x < min)
                    {
                        min = currentPos.x;
                    }

                    yield return(PlacePlaceholder(allQuestions[questionIndex], p, currentPos));

                    currentPos.x += (answerSize * sign) / 2;
                }

                var questionPos = currentPos;
                questionPos.y += bounds.LetterSize() * 1.35f;
                questionPos.x  = (max + min) / 2f;
                yield return(PlaceQuestion(allQuestions[questionIndex], questionPos));

                questionIndex++;
            }

            // give time to finish animating elements
            yield return(TimeEngine.Wait(0.65f));

            isAnimating = false;
        }
        public virtual IEnumerator GetPlaceCoroutine()
        {
            // Count questions and answers
            int questionsNumber    = 0;
            int placeHoldersNumber = 0;

            foreach (var q in allQuestions)
            {
                questionsNumber++;
                placeHoldersNumber += q.PlaceholdersCount();
            }

            var bounds = WorldBounds.Instance;

            // Text justification "algorithm"
            var gap = bounds.QuestionGap();

            float occupiedSpace = questionsNumber * questionSize + answerSize * placeHoldersNumber;

            if (alsoDrawing)
            {
                occupiedSpace += questionsNumber * 3f;
            }

            float blankSpace = gap - occupiedSpace;

            //  3 words => 4 white zones  (need increment by 1)
            //  |  O   O   O  |
            float spaceIncrement = blankSpace / (questionsNumber + 1);

            //Implement Line Break only if needed
            if (blankSpace <= bounds.HalfLetterSize() / 2f)
            {
                throw new InvalidOperationException("Need a line break becase 1 line is not enough for all");
            }

            var     flow = AssessmentConfiguration.Instance.LocaleTextFlow;
            float   sign;
            Vector3 currentPos;

            if (flow == AssessmentConfiguration.TextFlow.RightToLeft)
            {
                currentPos = bounds.ToTheRightQuestionStart();
                //currentPos.x -= answerSize / 2.0f;
                sign = -1;
            }
            else
            {
                currentPos    = bounds.ToTheLeftQuestionStart();
                currentPos.x += answerSize / 2.0f;
                sign          = 1;
            }

            currentPos.y -= 1.5f;

            int questionIndex = 0; //TODO: check if this redundant

            for (int i = 0; i < questionsNumber; i++)
            {
                currentPos.x += (spaceIncrement + questionSize / 2) * sign;
                yield return(PlaceQuestion(allQuestions[questionIndex], currentPos));

                currentPos.x += (questionSize * sign) / 2;

                if (alsoDrawing)
                {
                    currentPos.x += (3f * sign) / 2;
                    yield return(PlaceImage(allQuestions[questionIndex], currentPos));

                    currentPos.x += (3.3f * sign) / 2;
                    Debug.Log("PlacedImage######");
                }

                foreach (var p in allQuestions[questionIndex].GetPlaceholders())
                {
                    currentPos.x += (answerSize * sign) / 2;
                    yield return(PlacePlaceholder(allQuestions[questionIndex], p, currentPos));

                    currentPos.x += (answerSize * sign) / 2;
                }

                questionIndex++;
            }

            // give time to finish animating elements
            yield return(TimeEngine.Wait(0.65f));

            isAnimating = false;
        }
        public IEnumerator PlayCoroutine(Action gameEndedCallback)
        {
            yield return(PlayStartSound());

            bool AnturaShowed = false;

            for (int round = 0; round < Configuration.Rounds; round++)
            {
                #region Init
                QuestionGenerator.InitRound();

                for (int question = 0; question < Configuration.SimultaneosQuestions; question++)
                {
                    LogicInjector.Wire(
                        QuestionGenerator.GetNextQuestion(),
                        QuestionGenerator.GetNextAnswers());
                }

                LogicInjector.CompleteWiring();
                LogicInjector.EnableDragOnly(); //as by new requirments

                //mute feedback audio while speaker is speaking
                bool answerConfigurationCache = AssessmentConfiguration.Instance.PronunceAnswerWhenClicked;
                AssessmentConfiguration.Instance.PronunceAnswerWhenClicked = false;

                QuestionGenerator.CompleteRound();
                #endregion

                if (AnturaShowed)
                {
                    // Show question only after antura animation is done.
                    QuestionPlacer.Place(QuestionGenerator.GetAllQuestions());
                    while (QuestionPlacer.IsAnimating())
                    {
                        yield return(null);
                    }
                }

                AnswerPlacer.Place(QuestionGenerator.GetAllAnswers());
                while (AnswerPlacer.IsAnimating())
                {
                    yield return(null);
                }

                LogicInjector.AnswersAdded();

                if (AnturaShowed == false)
                {
                    #region ANTURA ANIMATION

                    PlayAnturaIsComingSound();
                    var anturaController = AnturaFactory.Instance.SleepingAntura();

                    anturaController.StartAnimation(() => PlayPushAnturaSound(), () => PlayAnturaGoneSound());

                    while (anturaController.IsAnimating())
                    {
                        yield return(null);
                    }

                    yield return(TimeEngine.Wait(0.3f));

                    yield return(PlayGameDescription());

                    #endregion

                    QuestionPlacer.Place(QuestionGenerator.GetAllQuestions());
                    while (QuestionPlacer.IsAnimating())
                    {
                        yield return(null);
                    }

                    AnturaShowed = true;
                }

                #region GamePlay
                //////////////////////////////
                //// GAME LOGIC (WIP)
                ////----
                // Restore audio when playing
                AssessmentConfiguration.Instance.PronunceAnswerWhenClicked = answerConfigurationCache;
                LogicInjector.EnableGamePlay();

                while (LogicInjector.AllAnswersCorrect() == false)
                {
                    yield return(null);
                }
                ////___
                //// GAME LOGIC END
                //////////////////////////////

                LogicInjector.RemoveDraggables();

                QuestionPlacer.RemoveQuestions();
                AnswerPlacer.RemoveAnswers();

                while (QuestionPlacer.IsAnimating() || AnswerPlacer.IsAnimating())
                {
                    yield return(null);
                }

                LogicInjector.ResetRound();
                #endregion
            }

            gameEndedCallback();
        }