Page 3 of 3

Re: Super Text Mesh Integration

Posted: Wed Jun 26, 2019 6:23 pm
by alfa995
Thank you! There's a small bug though. Even though the delay amount is calculated properly each node uses the length of the previous one instead of its own.

I think the variable is updated too late, so by the time the line is ready and calculated it already set the delay based on the previous value. So for example the first node gets skipped the first time (variable set to 0 at start) and every other time it uses the length of the last node in the conversation, since that's when the variable was last modified.

I tried running that code on the SubtitlePanel script, on ShowSubtitle, SetFormattedText, etc. but they don't seem to work either.

Re: Super Text Mesh Integration

Posted: Wed Jun 26, 2019 7:09 pm
by Tony Li
I left my example vague because I wasn't sure how you'd want to implement that part. For that part, assign subtitle.formattedText.text to a SuperTextMesh component. Then check its drawText.Length, such as:

SetSTMEndVar.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class SetSTMEndVar : MonoBehaviour 
{
    public SuperTextMesh stm; //<--ASSIGN IN INSPECTOR.

    void OnConversationLine(Subtitle subtitle)
    {
        stm.text = subtitle.formattedText.text;
        int numVisibleChars = stm.drawText.Length;
        float minSeconds = DialogueManager.displaySettings.GetMinSubtitleSeconds();
        float charsPerSecond = DialogueManager.displaySettings.GetSubtitleCharsPerSecond();
        float endValue = Mathf.Max(minSeconds, numVisibleChars / Mathf.Max(1, charsPerSecond));
        DialogueLua.SetVariable("end", endValue);
    }
}

Re: Super Text Mesh Integration

Posted: Wed Jun 26, 2019 10:39 pm
by alfa995
No no, the value of the end variable is correct. STM has a float SuperTextMesh.totalReadTime variable, it says "The total amount of time it will take the mesh to read out text, including animations" so that's already handled automatically, no need to calculate based on text length, just gotta access that variable. I just don't know where to call the DialogueLua.SetVariable for it to work.

Strangely, if I use the regular {{end}} keyword with the corresponding chars per second (2 chars per sec if the text has a 0.5 read delay for example) it works just fine (ignoring delays and draw animations though). So I think it's best to wait for that delegate to be implemented and plug the variable to give it the alternate value. Since my setup is so weird (involving DoozyUI animations, panels that hide/show when the speaker changes, etc) trying to do checks and update the variable in several spots it will get even messier.

Re: Super Text Mesh Integration

Posted: Thu Jun 27, 2019 8:39 am
by Tony Li
The code is simpler in that case:

SetSTMEndVar.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class SetSTMEndVar : MonoBehaviour 
{
    public SuperTextMesh stm; //<--ASSIGN IN INSPECTOR.

    void OnConversationLine(Subtitle subtitle)
    {
        stm.text = subtitle.formattedText.text;
        DialogueLua.SetVariable("end", stm.totalReadTime);
    }
}
I also updated the example above (using drawText.Length) with the full code for a script.

The {{end}} keyword and [var=end] tag are evaluated at the same time, so the timing won't be any different using a delegate function for {{end}}. However, your sequences will look nicer because {{end}} is more standard than [var=end].

Re: Super Text Mesh Integration

Posted: Thu Jun 27, 2019 9:05 am
by Tony Li
BTW, in the next update, you can use this script to set {{end}}:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class SetSTMEndVar  : MonoBehaviour
{
    public SuperTextMesh stm;

    private void Awake()
    {
        ConversationView.overrideGetDefaultSubtitleDuration = ComputeEndValue;
    }

    private float ComputeEndValue(string text)
    {
        stm.text = text;
        return stm.totalReadTime;
    }
}

Re: Super Text Mesh Integration

Posted: Thu Jun 27, 2019 6:54 pm
by alfa995
It's all working now, thank you so much for your help!

Re: Super Text Mesh Integration

Posted: Thu Jun 27, 2019 7:32 pm
by Tony Li
Glad to help!