Beispiel #1
0
    public IEnumerator PlayCaptionsWithAudio()
    {
        var words        = GetNumberOfWords();
        int WordsPerLine = 12;

        var TimePerLine = (src.clip.length)
                          /
                          (words.Length / WordsPerLine);

        var framerate = 1.0f / Time.fixedDeltaTime;

        if (AudioCaptions == null)
        {
            Debug.Log("No captions");
            yield break;
        }

        //set up video captions
        TextMeshProUGUI tmp = captionsCanvas;

        if (tmp == null)
        {
            Debug.LogWarning("couldnt find text");
        }

        int word  = 0;
        int start = 0;

        captionsEnded = false;

        while (true)
        {
            if (src == null)
            {
                yield break;
            }

            if (!src.isPlaying)
            {
                yield return(null);
            }

            string line = "";

            if (src != null)
            {
                word = (int)UIB_Utilities.Map(word + WordsPerLine, word + WordsPerLine, words.Length, src.time - .5f, src.clip.length);
            }
            else
            {
                yield break;
            }

            if (word < 0)
            {
                yield return(null);
            }

            for (int i = start; i < start + WordsPerLine; i++)
            {
                if (i < words.Length)
                {
                    line += words[i] + " ";
                }

                if (i >= words.Length)
                {
                    captionsEnded = true;
                }
            }

            captionsCanvas.text = line;

            if (src.isPlaying)
            {
                yield return(new WaitForSeconds(TimePerLine));

                start = start + WordsPerLine;
            }
            if (clipEnded && captionsEnded)
            {
                GetComponentInParent <DisplayedNarrativesBluetooth_Page>().StopPlaying(this);
                yield break;
            }
        }
    }