Browse Source

Add OnAllTextWritten to IWriterListener

Called once there are no Word tokesn left to be processed within a run of the Write method in Writer.
master
Steve Halliwell 5 years ago
parent
commit
b20e21b449
  1. 33
      Assets/Fungus/Scripts/Components/Writer.cs
  2. 6
      Assets/Fungus/Scripts/Components/WriterAudio.cs
  3. 5
      Assets/Fungus/Scripts/Interfaces/IWriterListener.cs

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

@ -25,7 +25,9 @@ namespace Fungus
/// <summary> Writing has resumed after a pause. </summary>
Resume,
/// <summary> Writing has ended. </summary>
End
End,
/// <summary> No text remaining to be written. </summary>
AllTextWritten,
}
/// <summary>
@ -79,6 +81,7 @@ namespace Fungus
protected float sizeValue = 16f;
protected bool inputFlag;
protected bool exitFlag;
protected bool hasTextRemaining;
protected List<IWriterListener> writerListeners = new List<IWriterListener>();
@ -227,6 +230,16 @@ namespace Fungus
return false;
}
protected virtual bool WordTokensRemaining(List<TextTagToken> tokens, int startingIndex)
{
for (int i = startingIndex; i < tokens.Count; i++)
{
if (tokens[i].type == TokenType.Words)
return true;
}
return false;
}
protected virtual IEnumerator ProcessTokens(List<TextTagToken> tokens, bool stopAudio, Action onComplete)
{
// Reset control members
@ -234,6 +247,7 @@ namespace Fungus
italicActive = false;
colorActive = false;
sizeActive = false;
hasTextRemaining = WordTokensRemaining(tokens, 0);
colorText = "";
sizeValue = 16f;
currentPunctuationPause = punctuationPause;
@ -257,6 +271,12 @@ namespace Fungus
// Notify listeners about new token
WriterSignals.DoTextTagToken(this, token, i, tokens.Count);
if(hasTextRemaining && !WordTokensRemaining(tokens, i))
{
hasTextRemaining = false;
NotifyAllTextWritten();
}
// Update the read ahead string buffer. This contains the text for any
// Word tags which are further ahead in the list.
if (doReadAheadText)
@ -847,6 +867,17 @@ namespace Fungus
}
}
protected virtual void NotifyAllTextWritten()
{
WriterSignals.DoWriterState(this, WriterState.AllTextWritten);
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnAllTextWritten();
}
}
protected virtual void NotifyEnd(bool stopAudio)
{
WriterSignals.DoWriterState(this, WriterState.End);

6
Assets/Fungus/Scripts/Components/WriterAudio.cs

@ -259,7 +259,11 @@ namespace Fungus
targetAudioSource.clip = voiceOverClip;
targetAudioSource.Play();
}
public void OnAllTextWritten()
{
}
#endregion
}
}

5
Assets/Fungus/Scripts/Interfaces/IWriterListener.cs

@ -28,10 +28,13 @@ namespace Fungus
/// Called when the Writer has resumed writing text.
void OnResume();
/// Called when the Writer has finished writing text.
/// Called when the Writer has finished.
/// <param name="stopAudio">Controls whether audio should be stopped when writing ends.</param>
void OnEnd(bool stopAudio);
/// Called when the Writer has no more text remaining, but may have waits or other tokens still pending.
void OnAllTextWritten();
/// Called every time the Writer writes a new character glyph.
void OnGlyph();

Loading…
Cancel
Save