private static TransitionElement GetTransition(string transitionPath)
        {
            var keys = transitionPath.Split('.');

            return(TransitionElements.Where(t => t.Transition.Key == keys[2] &&
                                            t.Transition.Parent.Key == keys[1] &&
                                            t.Transition.Parent.Parent.Key == keys[0]).First());
        }
        public void ReturnAllTransitions()
        {
            var q = from d in StateInfoConfig.Dialogs
                    from s in d.States
                    from t in s.Transitions
                    select t;

            Assert.AreEqual(q.Count(), TransitionElements.Count());
        }
    IEnumerator Transition(int transitionIndex)
    {
        yield return(new WaitForSeconds(0.05f));

        audioList = FindObjectOfType <AudioList>();
        yield return(new WaitForSeconds(introductionDelay));

        int fillerIndex = 0;

        transitioning = true;
        if (transitionElements[transitionIndex] != null)
        {
            if (transitionElements[transitionIndex].transitionBackgrounds.Count == 1)
            {
                if (transitionElements[transitionIndex].transitionBackgrounds[0] && transitionBackgroundPanel != null)
                {
                    transitionBackgroundPanel.sprite = transitionElements[transitionIndex].transitionBackgrounds[0];
                }
            }

            if (transitionElements[transitionIndex].transitionBackgrounds[0] == null)
            {
                for (int i = 0; i < runtimeChoices.chosenEnvironments.Length; i++)
                {
                    transitionElements[transitionIndex].environmentBackgrounds[i] = runtimeChoices.chosenEnvironments[i].environmentSprite;
                }

                transitionBackgroundPanel.sprite = transitionElements[transitionIndex].environmentBackgrounds[runtimeChoices.runTimeLoopCount - 1];
            }



            if (transitionIndex == 0)
            {
                fillerIndex = Random.Range(0, transitionElements[0].introFillers.Length);
                firstPart   = transitionElements[0].introFillers[fillerIndex];
            }

            if (transitionIndex != 18)
            {
                middleInfo.text = firstPart + transitionElements[transitionIndex].textElement[0].textInputs[runtimeChoices.runTimeLoopCount - 1];
                audioList.narratorVoiceLines.clip = transitionElements[transitionIndex].transitionVoiceLines[runtimeChoices.runTimeLoopCount - 1];
            }
            else if (transitionIndex == 18)
            {
                bool didHeroWin = false;
                foreach (PlayerItems item in runtimeChoices.playerItems)
                {
                    didHeroWin = (item.itemName == "Victory Shades") ? true : didHeroWin;
                }
                if (didHeroWin)
                {
                    middleInfo.text = transitionElements[transitionIndex].textElement[0].textInputs[0];
                    transitionBackgroundPanel.sprite  = transitionElements[transitionIndex].transitionBackgrounds[0];
                    audioList.narratorVoiceLines.clip = transitionElements[transitionIndex].transitionVoiceLines[0];
                }
                else
                {
                    middleInfo.text = transitionElements[transitionIndex].textElement[0].textInputs[1];
                    transitionBackgroundPanel.sprite  = transitionElements[transitionIndex].transitionBackgrounds[1];
                    audioList.narratorVoiceLines.clip = transitionElements[transitionIndex].transitionVoiceLines[1];
                }
            }
            else
            {
                middleInfo.text = "";
            }

            if (atTransitionDestinationScene == false)
            {
                yield return(new WaitForSeconds(0.5f));

                if (firstPart != "")
                {
                    transitionNarrator.DoVoiceFiller(fillerIndex);
                }
                yield return(new WaitForSeconds(0.1f));

                transitionNarrator.DoNarration(middleInfo.text);
            }
        }



        _nextTransitionElements = transitionElements[transitionIndex];

        float timeToLerp = transitionElements[transitionIndex].textElement[0].timeOfTextDisplayed;
        float timeLerped = 0;

        //Debug.Log("Doing Transition - " + _nextTransitionElements.details);

        float oppositeAlpha;

        if (_nextTransitionElements.startTransparent)
        {
            if (_TransitionCanvasGroup.alpha == 1)
            {
                _TransitionCanvasGroup.alpha = 0;
            }

            oppositeAlpha = 1;
        }
        else
        {
            if (_TransitionCanvasGroup.alpha == 0)
            {
                _TransitionCanvasGroup.alpha = 1;
            }
            oppositeAlpha = 0;
        }


        while (transitioning)
        {
            timeLerped += Time.fixedDeltaTime;
            _TransitionCanvasGroup.alpha = Mathf.Lerp(_TransitionCanvasGroup.alpha, oppositeAlpha, timeLerped / timeToLerp);

            if (oppositeAlpha == 1 && timeLerped > timeToLerp)
            {
                _TransitionCanvasGroup.alpha = 1;
                transitioning = false;
            }
            else if (oppositeAlpha == 0 && timeLerped > timeToLerp)
            {
                _TransitionCanvasGroup.alpha = 0;
                transitioning = false;
            }

            yield return(new WaitForSeconds(0.02f));
        }

        while (audioList.narratorVoiceLines.isPlaying || audioList.textToSpeechSource.isPlaying)
        {
            yield return(new WaitForSeconds(0.02f));
        }

        yield return(new WaitForSeconds(1f));

        if (atTransitionDestinationScene)
        {
            atTransitionDestinationScene = false;
        }
        else if (transitionIndex == 18)
        {
            FindObjectOfType <CustomSceneManager>().LoadCredits();
        }
        else
        {
            readyToLoadScene.Raise();
        }



        //   Debug.Log("Done with Transition");
    }
        public void SetHTo20ForAllTransitionsOfS1S2_S2S2_S3S2()
        {
            var trans = TransitionElements.Where(t => t.Transition.Parent.Parent.Key == "D3" && t.H != 20);

            Assert.AreEqual(0, trans.Count());
        }
        public void SetYTo185ForAllDialog2Transitions()
        {
            var trans = TransitionElements.Where(t => t.Transition.Parent.Parent.Key == "D2" && t.Y != 185);

            Assert.AreEqual(0, trans.Count());
        }
        public void SetHTo20ForAllDialog1Transitions()
        {
            var trans = TransitionElements.Where(t => t.Transition.Parent.Parent.Key == "D1" && t.H != 20);

            Assert.AreEqual(0, trans.Count());
        }