Example #1
0
        private IEnumerator RoundsCoroutine(KoreCallback gameEndedCallback)
        {
            int anturaGagRound = Random.Range(1, Configuration.NumberOfRounds);

            for (int round = 0; round < Configuration.NumberOfRounds; round++)
            {
                // Show antura only on the elected round.
                if (anturaGagRound == round)
                {
                    yield return(Koroutine.Nested(AnturaGag()));
                }
                InitRound();

                yield return(Koroutine.Nested(RoundBegin()));

                yield return(Koroutine.Nested(PlaceAnswers()));

                LogicInjector.EnableDragOnly();

                if (round == 0)
                {
                    executingRound0 = true;
                    Koroutine.Run(DescriptionAudio());
                }

                yield return(Koroutine.Nested(GamePlay()));

                executingRound0 = false;
                yield return(Koroutine.Nested(ClearRound()));
            }

            gameEndedCallback();
        }
Example #2
0
        private IEnumerator PlaceCoroutine()
        {
            var   positions = new List <Vector3>();
            float xMin      = placerOptions.LeftX + placerOptions.AnswerSize / 2f + 2.0f;
            float xMax      = placerOptions.RightX - placerOptions.AnswerSize / 2f - 1.0f;
            float yMin      = placerOptions.BottomY + 1.7f;
            float z         = placerOptions.DefaultZ;


            for (float x = xMin; x < xMax; x += placerOptions.AnswerSize + 0.2f)
            {
                int times = 0;
                for (float y = yMin; times < 3; y += 3.1f, times++)
                {
                    float dx  = Random.Range(-0.1f, 0.1f);
                    var   vec = new Vector3(x + dx, y, z);
                    positions.Add(vec);
                }
            }

            positions.Shuffle();

            playbackAnswers = new List <Answer>();
            foreach (var a in allAnswers)
            {
                yield return(Koroutine.Nested(PlaceAnswer(a, positions)));
            }
            yield return(Koroutine.Nested(PlayBackCorrectAnswers()));

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

            isAnimating = false;
        }
Example #3
0
        IEnumerator RemoveCoroutine()
        {
            foreach (var q in allQuestions)
            {
                foreach (var p in q.GetPlaceholders())
                {
                    yield return(Koroutine.Nested(FadeOutPlaceholder(p)));
                }
                foreach (var img in images)
                {
                    yield return(Koroutine.Nested(FadeOutImage(img)));
                }
                yield return(Koroutine.Nested(FadeOutQuestion(q)));
            }

            foreach (var box in boxesList)
            {
                box.Hide();
            }

            // give time to finish animating elements
            yield return(Wait.For(0.45f));

            isAnimating = false;
        }
Example #4
0
 // Update is called once per frame
 IEnumerator TestCoroutine(int i)
 {
     if (i > 0)
     {
         Koroutine.Run(Parallel(2 * i));
         yield return(Koroutine.Nested(TestCoroutine(i - 1)));
     }
 }
Example #5
0
        IEnumerator ReadQuestionAndReplyEvent()
        {
            yield return(Koroutine.Nested(
                             dialogues.PlayLetterDataCoroutine(cacheQuestionToRead)));

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

            yield return(Koroutine.Nested(dialogues.PlayLetterDataCoroutine(cacheAnswerToRead)));
        }
Example #6
0
        private IEnumerator RemoveCoroutine()
        {
            foreach (var a in allAnswers)
            {
                yield return(Koroutine.Nested(RemoveAnswer(a.gameObject)));
            }
            yield return(Wait.For(0.65f));

            isAnimating = false;
        }
Example #7
0
        private IEnumerator PlayBackCorrectAnswers()
        {
            playbackAnswers.Shuffle();
            foreach (var a in playbackAnswers)
            {
                yield return(Koroutine.Nested(a.PlayLetter()));

                yield return(Wait.For(0.3f));
            }
            playbackAnswers = null;
        }
Example #8
0
        IEnumerator Nested()
        {
            Debug.Log("Nested");
            yield return(null);

            Debug.Log("Nested");
            yield return(Koroutine.Nested(Nested2()));;
            Debug.Log("Nested");
            yield return(null);

            Debug.Log("Nested");
        }
Example #9
0
        IEnumerator Test1()
        {
            Debug.Log("A");
            yield return(null);

            Debug.Log("B");
            yield return(Koroutine.Nested(Nested()));

            Debug.Log("C");
            yield return(null);

            Debug.Log("D");
        }
Example #10
0
        private IEnumerator PlaceCoroutine()
        {
            // Text justification "algorithm"
            float spaceIncrement = 0.5f + letterSize;
            float occupiedSpace  = allAnswers.Length * spaceIncrement - 3.5f;

            var     flow = AssessmentOptions.Instance.LocaleTextDirection;
            float   sign;
            Vector3 currentPos = Vector3.zero;

            currentPos.y = -1;
            currentPos.z = 5;

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

            currentPos.y -= 1.5f;

            // Move answer so we can wrap them in bg.
            foreach (var a in allAnswers)
            {
                MoveAnswer(a, currentPos);
                currentPos.x += spaceIncrement * sign;
            }

            // Spawn BG
            SpawnLettersBG();

            // Spawn Answers.
            playbackAnswers = new List <Answer>();
            foreach (var a in allAnswers)
            {
                yield return(Koroutine.Nested(PlaceAnswer(a)));
            }

            yield return(Koroutine.Nested(PlayBackCorrectAnswers()));

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

            isAnimating = false;
        }
Example #11
0
        private IEnumerator ClearRound()
        {
            LogicInjector.RemoveDraggables();

            yield return(Koroutine.Nested(LogicInjector.AllAnsweredEvent()));

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

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

            LogicInjector.ResetRound();
        }
Example #12
0
        private IEnumerator RemoveCoroutine()
        {
            foreach (var a in allAnswers)
            {
                yield return(Koroutine.Nested(RemoveAnswer(a.gameObject)));
            }

            yield return(Wait.For(0.2f));

            bgBox.Hide();

            foreach (var p in placeholders)
            {
                RemovePlaceholder(p);
            }

            audioManager.PlayPoofSound();
            yield return(Wait.For(0.3f));

            isAnimating = false;
        }
Example #13
0
        IEnumerator Example()
        {
            var cube    = Instantiate(cubePrefab, transform.position, Quaternion.identity) as GameObject;
            var cubepos = cube.transform;

            for (int i = 0; i < 5; i++)
            {
                float   advancement = 0;
                Vector3 pos         = cubepos.position;

                while (advancement < 2)
                {
                    advancement     += Time.deltaTime * 2;
                    cubepos.position = new Vector3(pos.x + advancement, pos.y, pos.z);
                    yield return(null);
                }

                yield return(Koroutine.Nested(ShotBullet(cubepos)));
            }

            Destroy(cube);
            RestartAnimation();
        }
Example #14
0
        public override IEnumerator GetPlaceCoroutine(bool playAudio)
        {
            ResetAnimationsQueue();

            if (playAudio)
            {
                // warn our heirs
                Debug.LogWarning("playAudio, parameter not used for Categorization questions");
            }

            // Count questions and answers
            int questionsNumber    = 0;
            int placeHoldersNumber = 0;

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

            float occupiedSpace  = placeHoldersNumber * options.SlotSize;
            float blankSpace     = options.RightX - options.LeftX - occupiedSpace;
            float spaceIncrement = blankSpace / (questionsNumber + 1);

            var     flow = AssessmentOptions.Instance.LocaleTextDirection;
            float   sign;
            Vector3 currentPos = new Vector3(0, options.QuestionY - 3.5f, options.DefaultZ);

            if (flow == TextDirection.RightToLeft)
            {
                currentPos.x = options.RightX;
                sign         = -1;
            }
            else
            {
                currentPos.x = options.LeftX;
                sign         = 1;
            }

            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 += (options.SlotSize / 2) * sign;

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

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

                    PlacePlaceholder(p, currentPos);
                    currentPos.x += (options.SlotSize / 2) * sign;
                }

                var questionPos = currentPos;
                questionPos.y = options.QuestionY;
                questionPos.x = (max + min) / 2f;

                // Category questions never read the category
                PlaceQuestion(allQuestions[questionIndex], questionPos, false);

                WrapQuestionInABox(allQuestions[questionIndex]);
                foreach (var anim in AnimationsQueue)
                {
                    yield return(Koroutine.Nested(anim));
                }

                AnimationsQueue.Clear();

                questionIndex++;
            }

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

            isAnimating = false;
        }
Example #15
0
        IEnumerator ParallelCoroutine(IEnumerator enumerator)
        {
            yield return(Koroutine.Nested(enumerator));

            done = true;
        }
Example #16
0
        private IEnumerator RoundBegin()
        {
            bool playSound = AssessmentOptions.Instance.QuestionSpawnedPlaySound;

            yield return(Koroutine.Nested(PlaceQuestions(playSound)));
        }
Example #17
0
        private IEnumerator PlaceCoroutine()
        {
            allAnswers.Shuffle();

            List <Vector3> positions = new List <Vector3>();
            float          xMin      = placerOptions.LeftX + 2.0f;
            float          xMax      = placerOptions.RightX - 2.0f;
            float          yMin      = placerOptions.BottomY + 2.9f;
            float          z         = placerOptions.DefaultZ;

            float deltaX = xMax - xMin;

            int answerCount = 0;

            foreach (var a in allAnswers)
            {
                answerCount++;
            }

            float answerGap = placerOptions.AnswerSize + 0.5f;
            var   flow      = AssessmentOptions.Instance.LocaleTextDirection;

            while (answerCount > 0)
            {
                int answersInThisLine = Mathf.FloorToInt(deltaX / answerGap);
                if (answersInThisLine > answerCount)
                {
                    answersInThisLine = answerCount;
                }

                // space occupied by this line
                float lineSpace = (answersInThisLine - 1) * 0.5f + answersInThisLine * placerOptions.AnswerSize;
                // startin X position for an answer
                float startX    = (lineSpace / 2.0f) + (placerOptions.AnswerSize / 2.0f);
                float direction = -1;

                if (flow == TextDirection.LeftToRight) // Not Arabic
                {
                    startX    = -startX;
                    direction = 1;
                }

                for (int i = 0; i < answersInThisLine && answerCount > 0; i++, answerCount--)
                {
                    startX += direction * (0.5f + placerOptions.AnswerSize);
                    var position = new Vector3(startX, yMin, z);
                    positions.Add(position);
                }

                yMin += 3.5f;
            }

            positions.Shuffle();

            playbackAnswers = new List <Answer>();
            foreach (var a in allAnswers)
            {
                yield return(Koroutine.Nested(PlaceAnswer(a, positions)));
            }
            yield return(Koroutine.Nested(PlayBackCorrectAnswers()));

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

            isAnimating = false;
        }
Example #18
0
        public virtual IEnumerator GetPlaceCoroutine(bool playAudio)
        {
            ResetAnimationsQueue();

            // Count questions and answers
            int questionsNumber    = 0;
            int placeHoldersNumber = 0;

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

            float questionSize  = options.QuestionSize;
            float occupiedSpace =
                placeHoldersNumber * options.SlotSize
                + questionsNumber * options.QuestionSize;

            if (options.SpawnImageWithQuestion)
            {
                occupiedSpace += options.ImageSize;
            }

            float blankSpace     = options.RightX - options.LeftX - occupiedSpace;
            float spaceIncrement = blankSpace / (questionsNumber + 1);

            var     flow = AssessmentOptions.Instance.LocaleTextDirection;
            float   sign;
            Vector3 currentPos = new Vector3(0, options.QuestionY, options.DefaultZ);

            if (flow == TextDirection.RightToLeft)
            {
                currentPos.x = options.RightX;
                sign         = -1;
            }
            else
            {
                currentPos.x = options.LeftX;
                sign         = 1;
            }

            int questionIndex = 0;

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

                if (options.SpawnImageWithQuestion)
                {
                    currentPos.x += (sign * options.ImageSize) / 1.8f;
                    PlaceImage(allQuestions[questionIndex], currentPos);
                    currentPos.x += (sign * options.ImageSize) / 1.8f;
                }

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

                WrapQuestionInABox(allQuestions[questionIndex]);
                foreach (var anim in AnimationsQueue)
                {
                    yield return(Koroutine.Nested(anim));
                }

                AnimationsQueue.Clear();
                questionIndex++;
            }

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

            isAnimating = false;
        }