最近做的一个效果让下面为了让下面这种图片生成一个翻页效果(使用ShaderGraph中的FlipBook节点),我通过协程来实现连续翻页。
先是定义一个Coroutine coroutine = null;
然后在一定情况下执行coroutine = StartCoroutine(KeepPreview(texSheet));这样这个协程就可以连续执行起来了,达到通过WaitForSeconds来控制翻页进度的目的。
IEnumerator KeepPreview(TexSheet texSheet)
{
if (texSheet)
{
float frameRate = Mathf.Abs(texSheet.frameRate);
if (frameRate < 0.01f)
{
yield return null;
}
else
{
float interval = 1 / frameRate;
yield return new WaitForSeconds(interval);
texSheet.UpdateSheetIndex();
}
coroutine = StartCoroutine(KeepPreview(texSheet));
}
}
本来在编辑器里面是比较正常的,但是发布成WebG