Browse Source

Writer character delay counter modification

- more consistent character pacing
- prevents the 1 character per frame limit, fixed by timer increment after return from yield
master
desktop-maesty/steve 5 years ago
parent
commit
2b8d0cd87e
  1. 20
      Assets/Fungus/Scripts/Components/Writer.cs

20
Assets/Fungus/Scripts/Components/Writer.cs

@ -495,6 +495,7 @@ namespace Fungus
UpdateCloseMarkup();
float timeAccumulator = Time.deltaTime;
float invWritingSpeed = 1f / currentWritingSpeed;
for (int i = 0; i < param.Length + 1; ++i)
{
@ -510,6 +511,7 @@ namespace Fungus
yield return null;
}
//actually grab the next chars
PartitionString(writeWholeWords, param, i);
ConcatenateString(startText);
textAdapter.Text = outputString.ToString();
@ -533,13 +535,19 @@ namespace Fungus
// Delay between characters
if (currentWritingSpeed > 0f)
{
if (timeAccumulator > 0f)
timeAccumulator -= invWritingSpeed;
if (timeAccumulator <= 0f)
{
timeAccumulator -= 1f / currentWritingSpeed;
}
else
{
yield return new WaitForSeconds(1f / currentWritingSpeed);
if (invWritingSpeed > Time.deltaTime)
{
yield return new WaitForSeconds(invWritingSpeed);
timeAccumulator += invWritingSpeed;
}
else
{
yield return null;
timeAccumulator += Time.deltaTime;
}
}
}
}

Loading…
Cancel
Save