Browse Source

Click to instant complete text writing

master
chrisgregan 10 years ago
parent
commit
b5aa348fb4
  1. 53
      Assets/Fungus/Dialog/Scripts/Dialog.cs
  2. BIN
      ProjectSettings/EditorBuildSettings.asset
  3. BIN
      ProjectSettings/ProjectSettings.asset

53
Assets/Fungus/Dialog/Scripts/Dialog.cs

@ -131,23 +131,10 @@ namespace Fungus
} }
// Zero speed means write instantly // Zero speed means write instantly
// Also write instantly if text contains rich text markup tags
if (currentSpeed == 0 || if (currentSpeed == 0 ||
text.Contains("<")) text.Contains("<"))
{ {
foreach (Glyph glyph in glyphs) currentSpeed = 10000;
{
if (glyph.type == GlyphType.Character)
{
storyText.text += glyph.param;
}
}
if (onWritingComplete != null)
{
onWritingComplete();
}
yield break;
} }
GameObject typingAudio = null; GameObject typingAudio = null;
@ -160,12 +147,6 @@ namespace Fungus
typingAudio.audio.loop = loopWritingSound; typingAudio.audio.loop = loopWritingSound;
typingAudio.audio.Play(); typingAudio.audio.Play();
} }
float writeDelay = 0f;
if (currentSpeed > 0)
{
writeDelay = (1f / (float)currentSpeed);
}
float timeAccumulator = 0f; float timeAccumulator = 0f;
@ -174,16 +155,13 @@ namespace Fungus
{ {
timeAccumulator += Time.deltaTime; timeAccumulator += Time.deltaTime;
bool skipWriting = false; float writeDelay = 0f;
/* if (currentSpeed > 0)
if (Input.GetMouseButtonDown(0))
{ {
skipWriting = true; writeDelay = (1f / (float)currentSpeed);
} }
*/
while (skipWriting || while (timeAccumulator > writeDelay)
timeAccumulator > writeDelay)
{ {
timeAccumulator -= writeDelay; timeAccumulator -= writeDelay;
@ -220,6 +198,11 @@ namespace Fungus
} }
storyText.text += start + glyph.param + end; storyText.text += start + glyph.param + end;
if (Input.GetMouseButtonDown(0))
{
currentSpeed = 10000; // Write instantly
}
} }
// Add a wait glyph on punctuation marks // Add a wait glyph on punctuation marks
@ -247,9 +230,10 @@ namespace Fungus
glyphs[i + 1].type == GlyphType.Character && glyphs[i + 1].type == GlyphType.Character &&
IsPunctuation(glyphs[i + 1].param)); IsPunctuation(glyphs[i + 1].param));
if (!skipCharacter && if (!skipCharacter)
!skipWriting) {
yield return new WaitForSeconds(currentPunctuationPause); yield return new WaitForSeconds(currentPunctuationPause);
}
} }
break; break;
@ -285,16 +269,14 @@ namespace Fungus
{ {
duration = 1f; duration = 1f;
} }
if (!skipWriting) yield return new WaitForSeconds(duration);
{ timeAccumulator = 0f;
yield return new WaitForSeconds(duration);
timeAccumulator = 0f;
}
break; break;
case GlyphType.WaitForInputNoClear: case GlyphType.WaitForInputNoClear:
OnWaitForInputTag(true); OnWaitForInputTag(true);
yield return StartCoroutine(WaitForInput(null)); yield return StartCoroutine(WaitForInput(null));
timeAccumulator = 0f;
OnWaitForInputTag(false); OnWaitForInputTag(false);
break; break;
@ -302,11 +284,13 @@ namespace Fungus
OnWaitForInputTag(true); OnWaitForInputTag(true);
yield return StartCoroutine(WaitForInput(null)); yield return StartCoroutine(WaitForInput(null));
OnWaitForInputTag(false); OnWaitForInputTag(false);
timeAccumulator = 0f;
storyText.text = ""; storyText.text = "";
break; break;
case GlyphType.Clear: case GlyphType.Clear:
storyText.text = ""; storyText.text = "";
timeAccumulator = 0f;
break; break;
case GlyphType.Speed: case GlyphType.Speed:
@ -315,6 +299,7 @@ namespace Fungus
currentSpeed = 0f; currentSpeed = 0f;
} }
writeDelay = 0; writeDelay = 0;
timeAccumulator = 0f;
if (currentSpeed > 0) if (currentSpeed > 0)
{ {
writeDelay = (1f / (float)currentSpeed); writeDelay = (1f / (float)currentSpeed);

BIN
ProjectSettings/EditorBuildSettings.asset

Binary file not shown.

BIN
ProjectSettings/ProjectSettings.asset

Binary file not shown.
Loading…
Cancel
Save