private void CheckSubtitles() { SubtitleBlock subtitleBlock = _srtParser.GetForTime((float)_videoPlayer.time); if (subtitleBlock.Index != _currentSubtitleIndex) { ShowSubtitle(subtitleBlock); _currentSubtitleIndex = subtitleBlock.Index; } }
private void VideoPlayerOnloopPointReached(VideoPlayer source) { SubtitleBlock subtitleBlock = _srtParser.GetForTime((float)_videoPlayer.time); if (subtitleBlock.Index != _currentSubtitleIndex) { ShowSubtitle(subtitleBlock); _currentSubtitleIndex = subtitleBlock.Index; } OnVideoClipFinished?.Invoke(source.clip); }
public IEnumerator Begin() { var currentlyDisplayingText = Text; var fadedOutText = Text2; currentlyDisplayingText.text = string.Empty; fadedOutText.text = string.Empty; currentlyDisplayingText.gameObject.SetActive(true); fadedOutText.gameObject.SetActive(true); var parser = new SRTParser(Subtitle); var startTime = Time.time; SubtitleBlock currentSubtitle = null; while (true) { var elapsed = Time.time - startTime; var subtitle = parser.GetForTime(elapsed); if (subtitle != null) { if (!subtitle.Equals(currentSubtitle)) { currentSubtitle = subtitle; // Swap references around var temp = currentlyDisplayingText; currentlyDisplayingText = fadedOutText; fadedOutText = temp; // Switch subtitle text currentlyDisplayingText.text = currentSubtitle.Text; // Yield a bit for the fade out to get part-way yield return(new WaitForSeconds(FadeTime / 3)); // Fade in the new current //yield return FadeTextIn(currentlyDisplayingText); } yield return(null); } else { currentlyDisplayingText.gameObject.SetActive(false); fadedOutText.gameObject.SetActive(false); yield break; } } }
private void ShowSubtitle(SubtitleBlock subtitleBlock) { // if(_currentSubtitleIndex > 0) // { // OnHideSubtitle?.Invoke(_srtParser._subtitles[_currentSubtitleIndex - 1].Text); // } if (subtitleBlock != SubtitleBlock.Blank) { OnShowSubtitle?.Invoke(subtitleBlock.Text); } else if (_currentSubtitleIndex > 0) { OnHideSubtitle?.Invoke(_srtParser._subtitles[_currentSubtitleIndex - 1].Text); } if (_showSubtitles) { _subtitlePanel.SetText(subtitleBlock.Text); } }