任意のタイミングでPlayDemo()を呼びだすと、0文字からメッセージ送り速度に従って表示文字数を増やしていきます。
engine.Config.GetTimeSendChar(readMessage); で1文字を進めるのに必要な時間(秒)が取得できるので、それを使って表示文字数を調整します。
実際のノベル部分では、宴の独自のタグ処理や自動改行処理などが必要なので、
専用のテキストコンポーネントを使う必要があるなど色々違うのですが、
簡易的なデモ表示ならこれだけで大丈夫だと思います。
using UnityEngine;
using UnityEngine.UI;
namespace Utage
{
//メッセージスピードのデモ表示のサンプル
public class SampleMessageSpeedDemo : MonoBehaviour
{
[SerializeField]
AdvEngine engine;
//既読メッセージのスピードならtrue
[SerializeField]
bool readMessage = false;
//表示するテキスト文字
[SerializeField]
string message = "メッセージ速度のデモのテキスト";
//実際に表示をするTextコンポーネント
[SerializeField]
Text text;
bool IsPlaying { get; set; }
bool IsFirst { get; set; }
int CurrentTextLength { get; set; }
int TextLengthMax { get { return message.Length; } }
float DeltaTime { get; set; }
public void PlayDemo()
{
IsPlaying = true;
IsFirst = true;
CurrentTextLength = 0;
DeltaTime = 0;
}
void Update()
{
if (IsPlaying)
{
UpdateText();
}
}
void UpdateText()
{
if (IsFirst)
{
//最初のフレームだけ長さ0をいったん表示
CurrentTextLength = 0;
IsFirst = false;
}
else
{
//文字送り
float timeCharSend = engine.Config.GetTimeSendChar(readMessage);
SendChar(timeCharSend);
}
text.text = message.Substring(0, CurrentTextLength);
if (CurrentTextLength>= TextLengthMax)
{
IsPlaying = false;
}
}
void SendChar(float timeCharSend)
{
if (timeCharSend <= 0)
{
CurrentTextLength = TextLengthMax;
return;
}
DeltaTime += UnityEngine.Time.deltaTime;
while (DeltaTime >= 0)
{
++CurrentTextLength;
DeltaTime -= timeCharSend;
if (CurrentTextLength > TextLengthMax)
{
CurrentTextLength = TextLengthMax;
break;
}
}
}
}
}