internal void ShowDialog(Dialog dialog, Sprite avatar = null, DialogEndAction endAction = null) { currentDialog = dialog; avatarImage.sprite = avatar; StartCoroutine(getAllLines(endAction)); }
private IEnumerator getAllLines(DialogEndAction endAction) { var speakActors = FindObjectsOfType<TalkingActor>().ToDictionary(e => e.EntityID, j => j); var dialog = currentDialog ?? new Dialog(); var hasError = false; foreach (var actorID in dialog.DialogLines.Select(e => e.ActorID).Distinct().Where(actorID => !speakActors.ContainsKey(actorID))) { Debug.LogErrorFormat("Scene doesn't contains TalkingActor for {0}", actorID); hasError = true; } if (hasError) yield break; Controller.CursorManager.SetCursor(); Controller.HidingController.DisableInput(); dialogueBlocker.Activate(); dialogueBlocker.clicked = false; panel.SetActive(true); foreach (var item in dialog.DialogLines) { var currentActor = speakActors[item.ActorID]; currentActor.StartSpeak(); textObject.text = item.Text; if (item.ActorID == EnumActorID.MainCharacter) { textObject.color = MainCharacterLineColor; avatarCharacterImage.color = SpeakingCharacterHeadColor; avatarImage.color = avatarImage.sprite != null ? OtherCharacterHeadColor : Transparent; textObject.alignment = TextAnchor.UpperLeft; } else { textObject.color = OtherCharacterLineColor; avatarCharacterImage.color = OtherCharacterHeadColor; avatarImage.color = avatarImage.sprite != null ? SpeakingCharacterHeadColor : Transparent; textObject.alignment = TextAnchor.UpperRight; } bool dabingAudioFound = false; if (item.AudioFile != null && dabingAudioSource != null) { dabingAudioSource.clip = item.AudioFile; dabingAudioSource.Play(); dabingAudioFound = true; } dialogueBlocker.WaitForClick(Input.GetMouseButtonDown(0)); yield return new WaitUntil(() => dialogueBlocker.clicked || (dabingAudioFound && !dabingAudioSource.isPlaying)); dialogueBlocker.clicked = false; //yield return new WaitForSeconds(item.Duration); currentActor.EndSpeak(); } panel.SetActive(false); dialogueBlocker.Deactivate(); Controller.HidingController.EnableInput(); if (endAction != null) { endAction(); } }