-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCutsceneController.DialogPageAction.cs
45 lines (39 loc) · 1.53 KB
/
CutsceneController.DialogPageAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections;
using UnityEngine;
class DialogPageAction : ICutsceneAction {
private DialogPage _dialogPage;
private IPagedDialogController _pagedDialogController;
private Action _completion;
private Coroutine _waitToReadCoroutine;
private bool _isCompleted;
public DialogPageAction(DialogPage dialogPage, IPagedDialogController pagedDialogController) {
_dialogPage = dialogPage;
_pagedDialogController = pagedDialogController;
_pagedDialogController.AttachToNextBtnClickEvent(OnNextPageBtnClick);
}
public void Run(ICutsceneController controller, Action completion) {
var startTime = Time.time;
_completion = completion;
_pagedDialogController.AnimateTextInDialogPage(_dialogPage.Text, () => {
var timeToWait = Mathf.Max(0, _dialogPage.ReadingTime - (Time.time - startTime));
_waitToReadCoroutine = controller.StartCoroutine(Wait(timeToWait, completion));
});
}
private IEnumerator Wait(float seconds, Action completion) {
yield return new WaitForSeconds(seconds);
Complete();
}
private void OnNextPageBtnClick(ICutsceneController controller) {
if (_waitToReadCoroutine != null)
controller.StopCoroutine(_waitToReadCoroutine);
Complete();
}
private void Complete() {
if (_isCompleted)
return;
_pagedDialogController.DetachFromNextBtnClickEvent(OnNextPageBtnClick);
_completion();
_isCompleted = true;
}
}