private void Reset() { PlayerState = DialogPlayerState.NotPlaying; CurrentSection = 0; CurrentPlaceInSection = 0; CurrentSectionText = string.Empty; }
public bool PlayDialog() { if (IsPlaying || CurrentDialog == null) { return(false); } Reset(); PlayerState = DialogPlayerState.ShouldBePlaying; OnStartedPlaying(); InvokeRepeating("PlayCurrentSection", fadeInTime, fadeInTime); return(true); }
void PlayCurrentSection() { if (PlayerState == DialogPlayerState.ShouldFinishPlaying) { CancelInvoke("PlayCurrentSection"); return; } PlayerState = DialogPlayerState.IsPlaying; if (CurrentSection >= CurrentDialog.Sections.Count) { PlayerState = DialogPlayerState.FinishedPlaying; CancelInvoke("PlayCurrentSection"); return; } DialogSection ourCurrentSection = CurrentDialog.Sections[CurrentSection]; if (CurrentPlaceInSection == 0 && ourCurrentSection.SectionText.Length > 0) { OnSectionStarted(ourCurrentSection); } if (CurrentPlaceInSection >= ourCurrentSection.SectionText.Length) { CancelInvoke("PlayCurrentSection"); CurrentSectionText = ourCurrentSection.SectionText; OnTextUpdated(CurrentSectionText); OnSectionFinished(ourCurrentSection); if (DonePlayingEntireDialog) { PlayerState = DialogPlayerState.FinishedPlaying; CurrentDialog.HasPlayed = true; OnFinishedPlaying(); } } else { CurrentSectionText += ourCurrentSection.SectionText[CurrentPlaceInSection]; OnTextUpdated(CurrentSectionText); CurrentPlaceInSection++; } }
public DialogPlayer() { CurrentSection = 0; CurrentPlaceInSection = 0; PlayerState = DialogPlayerState.NotPlaying; }