Beispiel #1
0
    public void UpdateCode()
    {
        string[] lines = codeText.text.Split('\n');

        if (codeText.textInfo.lineCount != _currentlLineCount)
        {
            _currentlLineCount = lines.Length;
            string lineString = "";
            for (int i = 1; i < _currentlLineCount + 1; i++)
            {
                lineString += i;
                if (System.String.IsNullOrEmpty(lines[i - 1]))
                {
                    lineString += "\n";
                }
                else
                {
                    TMP_TextInfo info      = codeText.GetTextInfo(lines[i - 1]);
                    int          lineCount = info.lineCount;
                    if (lineCount < 1)
                    {
                        lineCount = 1;
                    }
                    for (int j = 0; j < lineCount; j++)
                    {
                        lineString += "\n";
                    }
                }
            }
            codeText.SetText(codeText.text);
            lineText.text = lineString;
        }
    }
Beispiel #2
0
    void Update()
    {
        if (mode == 0)
        {
            // Set the TMP object to show all of the currentDialog string, so we can
            // calculate line lengths in order to show characters one at a time.
            tmp.text            = currentDialog;
            tmp.maxVisibleLines = 3;
            // Need to call this for GetTextInfo() to work.
            tmp.ForceMeshUpdate();
            mode = 1;

            // Use the lastCharacterIndex of each line to split up the source string into lines,
            // in order to manage line display
            TMP_LineInfo[] lineInfoList = tmp.GetTextInfo(tmp.text).lineInfo;
            lineStrings = new List <string>();

            foreach (TMP_LineInfo lineInfo in lineInfoList)
            {
                int last  = lineInfo.lastCharacterIndex;
                int first = lineInfo.firstCharacterIndex;

                // Not sure why but lineinfo has garbage at the end where first/last are zero, so stop in this case.
                if (first == 0 && last == 0)
                {
                    break;
                }

                // sometimes line infos go past whats visible idk why
                if (first >= currentDialog.Length)
                {
                    break;
                }

                lineStrings.Add(currentDialog.Substring(first, (last - first) + 1));
            }

            // Keeps track of where to start pulling lines out of lineStrings
            currentLineIndex = 0;

            setLines(tmp, lineStrings, currentLineIndex, tmp.maxVisibleLines);

            tmp.maxVisibleCharacters = 0;
        }
        else if (mode == 1)
        {
            tmp.maxVisibleCharacters++;

            if (tmp.maxVisibleCharacters >= tmp.GetTextInfo(tmp.text).characterCount)
            {
                mode = 2;
            }
        }
        else if (mode == 2 && Input.GetButtonDown("Jump"))
        {
            // remove the first line.
            currentLineIndex++;

            // If this is true then the last line of dialogue already finished, so exit (or reset in this case.)
            if (currentLineIndex > lineStrings.Count - tmp.maxVisibleLines)
            {
                mode     = 3;
                tmp.text = "";
            }
            else
            {
                setLines(tmp, lineStrings, currentLineIndex, tmp.maxVisibleLines);
                tmp.maxVisibleCharacters = tmp.GetTextInfo(tmp.text).lineInfo[tmp.maxVisibleLines - 2].lastCharacterIndex;
                mode = 1;
            }
        }
        else if (mode == 3)
        {
            // Do nothing, text is done for now.
        }
    }
Beispiel #3
0
    IEnumerator SpeakPhrases()
    {
        count = 0;
        Quaternion iRot = talkingAnimator.transform.rotation;

        if (talkerLookat != null)
        {
            yield return(new WaitForSeconds(2f));

            Debug.Log("looking");
            float          curTime = 0f;
            AnimationCurve curve   = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
            while (curTime < 1f)
            {
                curTime += Time.deltaTime;
                talkingAnimator.transform.rotation = Quaternion.Lerp(iRot, Quaternion.LookRotation(talkerLookat.position - talkingAnimator.transform.position, Vector3.up), curTime);
                yield return(null);
            }
        }
        yield return(new WaitForSeconds(prePause));

        for (int i = 0; i < phrases.Length; i++)
        {
            text1.maxVisibleCharacters = 0;
            text2.maxVisibleCharacters = 0;

            yield return(new WaitForSeconds(phrases[i].delayTime));

            text1.text = phrases[i].text;
            text2.text = phrases[i].text;
            text1.ForceMeshUpdate();
            text2.ForceMeshUpdate();
            int charlength = text1.GetTextInfo(phrases[i].text).characterCount;
            Debug.Log(charlength + ", " + phrases[i].text);
            if (talkingAnimator != null)
            {
                talkingAnimator.SetBool("Talking", true);
            }
            for (int j = 1; j <= charlength; j++)
            {
                count = (count + 1) % factor;
                if (count == 0 && speakerAudio != null)
                {
                    speakerAudio.PlayOneShot(syllables[Random.Range(0, syllables.Length)]);
                }
                yield return(new WaitForSeconds(1f / charsPerSecond));

                text1.maxVisibleCharacters = j;
                text2.maxVisibleCharacters = j;
            }
            if (talkingAnimator != null)
            {
                talkingAnimator.SetBool("Talking", false);
            }
            yield return(new WaitForSeconds(phrases[i].sustainTime));

            text1.text = "";
            text2.text = "";
        }
        if (talkerLookat != null)
        {
            Debug.Log("looking");
            float          curTime = 0f;
            AnimationCurve curve   = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
            while (curTime < 1f)
            {
                curTime += Time.deltaTime;
                talkingAnimator.transform.rotation = Quaternion.Lerp(iRot, Quaternion.LookRotation(talkerLookat.position - talkingAnimator.transform.position, Vector3.up), 1f - curTime);
                yield return(null);
            }
        }
        if (AfterChatSequence != null)
        {
            AfterChatSequence.Invoke();
        }
        yield return(new WaitForSeconds(afterEventDelay));

        if (AfterChatSequenceDelayed != null)
        {
            AfterChatSequenceDelayed.Invoke();
        }
    }