private void Awake() { Instance = this; IsRuntime = true; // If first load, save the vars and set the first load flag to false if (DialogFilesManager.FirstLoad() || forceFirstGameLoad) { DialogFilesManager.SaveVariables(variables); DialogFilesManager.SetFirstLoad(false); } VariablesContainer vars = DialogFilesManager.GetVariablesFromDisk(); VariablesContainer = vars; }
/// <summary> /// Stops playing the dialog. If the dialog isn't playing, does nothing. Sets the <see cref="Playing"/> flag to false. /// After all that, if the saveModifiedVariable argument is set to true, saves the variables. /// </summary> /// <param name="saveModifiedVariables">Should the dialog player save the variable right now?</param> public virtual void StopPlayingDialog(bool saveModifiedVariables) { if (!Playing) { return; } StopCoroutine(PlayDialog(saveModifiedVariables)); Playing = false; if (saveModifiedVariables) { DialogFilesManager.SaveVariables(DialogEngineRuntime.Instance.VariablesContainer); } }
/// <summary> /// The enumerator associated to the coroutine responsible of the dialog playing process. This coroutine /// handles the delay, the choices, and the end of dialogs. You can also override it. To do so, please /// refer to the documentation. /// </summary> /// <param name="saveModifiedVariables">Should the coroutine save the variables after interpreting the last node of the dialog?</param> /// <returns></returns> public virtual IEnumerator PlayDialog(bool saveModifiedVariables) { #if (ENABLE_DEBUG_DIALOG) Debug.Log("Start of the dialog."); #endif float nextDelay; yield return(new WaitForSeconds(0.1f)); while (!dialogInterpreter.EndOfDialog) // While we aren't at the end of the dialog { if (choiceMade == ChoiceWaitingAnswer) { yield return(new WaitUntil(() => choiceMade != ChoiceWaitingAnswer)); dialogInterpreter.ChosenReply = choiceMade; } choiceMade = NoChoiceCurrently; if (ProcessNextNode(out nextDelay)) { yield return(new WaitForSeconds(nextDelay)); } else { break; } } if (saveModifiedVariables) { DialogFilesManager.SaveVariables(DialogEngineRuntime.Instance.VariablesContainer); } CurrentReplySubtitles = ""; #if (ENABLE_DEBUG_DIALOG) Debug.Log("End of the dialog."); #endif }