You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
namespace XWFramework.Tools
{
public class DialoguePlayer
{
public Action PlayFinish;
public const float defaultSpeed = 0.05f;//ÿ¸ö×Ö²¥·ÅËÙ¶È
public IEnumerator IETextPlayer(string content, Action<string> setText,Action finished,float playSpeed = defaultSpeed)
{
PlayFinish = finished;
int len = content.Length;
for (int i = 0; i <= len; i++)
{
yield return new WaitForSeconds(playSpeed);
var str = content.Substring(0, i);
setText?.Invoke(str);
}
yield return new WaitForSeconds(0.1f);
Finished();
}
public IEnumerator IETextPlayer(string content, Action<string> setText,float playSpeed = defaultSpeed)
{
int len = content.Length;
for (int i = 0; i <= len; i++)
{
yield return new WaitForSeconds(playSpeed);
var str = content.Substring(0, i);
setText?.Invoke(str);
}
yield return new WaitForSeconds(0.1f);
}
public void Finished()
{
PlayFinish?.Invoke();
PlayFinish = null;
}
}
}