Forum rules - please read before posting.

best way to control textScrollSpeed from speech text

I want to control textScrollSpeed from inside the actual test, like so:
<50>these chars will be printed with 50 speed. <100> these chars will be printed with 100 speed
(to get a ace attorney like text speed control)

The way I think of now involves accessing a private prop, so there must be another way:
I was thinking about creating a custom action extending ActionList, then in its run method read the tags from protected Speech speech and control the textScrollSpeed,
the problem is that speech.currentCharIndex is private.

Can you give me a hint of how to do this otherwise?

Comments

  • Welcome to the community, @eran.

    This is a good case for the use of "speech event tokens" - see the Manual chapter of the same name, which provides details and examples.

    To change the value of any Manager field through script, right-click that field's label and select "Copy script variable". In the case of the Speech Manager's "Text scroll speed" field, it's:

    AC.KickStarter.speechManager.textScrollSpeed
    

    With a speech event token, you could modify this in your speech text with e.g.:

    [textspeed:50]these chars will be printed with 50 speed. [textspeed:100] these chars will be printed with 100 speed

  • edited September 2023

    Hello!

    I wanted to do this thing, here is the code I wrote. Seems to work?

    `
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;

    public class SpeechTokenMonitor : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {

    }
    
    // Update is called once per frame
    void Update()
    {
    
    }
    private void OnEnable()
    {
        KickStarter.dialog.SpeechEventTokenKeys = new string[1] { "textspeed" };
        EventManager.OnSpeechToken += OnSpeechToken;
    }
    private void OnDisable()
    {
        EventManager.OnSpeechToken -= OnSpeechToken;
    }
    private void OnSpeechToken(AC.Char speakingCharacter, int lineID,
    string tokenKey, string tokenValue)
    {
        // Try to parse the tokenValue string to a float
        if (float.TryParse(tokenValue, out float parsedValue))
        {
            AC.KickStarter.speechManager.textScrollSpeed = parsedValue;
            Debug.Log(speakingCharacter + " said token [" + tokenKey + ":" + parsedValue + "]");
        }
        else
        {
            Debug.LogError("Failed to parse token value as float: " + tokenValue);
        }
    }
    

    }
    `

  • I placed this script on the game Engine Object, I also wrote this other Script on the subtitles UI Prefab so that the Scroll speed would rest after every line

    `using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;

    public class TextScrollDefaults : MonoBehaviour
    {
    public float TextScrollSpeed = 90;
    // Start is called before the first frame update
    void Start()
    {

    }
    private void OnEnable()
    {
        AC.KickStarter.speechManager.textScrollSpeed = TextScrollSpeed;
    }
    // Update is called once per frame
    void Update()
    {
    
    }
    

    }`

  • Looks good - but you'll need to check the value of "tokenKey" before parsing it, so that you don't run the code for other tokens, e.g. [wait].

    using UnityEngine;
    using AC;
    
    public class SpeechTokenMonitor : MonoBehaviour
    {
    
        private void OnEnable()
        {
            KickStarter.dialog.SpeechEventTokenKeys = new string[1] { "textspeed" };
            EventManager.OnSpeechToken += OnSpeechToken;
        }
    
        private void OnDisable()
        {
            EventManager.OnSpeechToken -= OnSpeechToken;
        }
    
        private void OnSpeechToken (AC.Char speakingCharacter, int lineID, string tokenKey, string tokenValue)
        {
            if (tokenKey != textspeed) return;
            // Try to parse the tokenValue string to a float
            if (float.TryParse (tokenValue, out float parsedValue))
            {
                AC.KickStarter.speechManager.textScrollSpeed = parsedValue;
                Debug.Log(speakingCharacter + " said token [" + tokenKey + ":" + parsedValue + "]");
            }
            else
            {
                Debug.LogWarning("Failed to parse token value as float: " + tokenValue);
            }
        }
    
    }
    
  • Ahh, good catch, thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.