From dba3161dc36e0a22b6d6dcddaa066dc91b7032ca Mon Sep 17 00:00:00 2001 From: "TITAN\\ckilg" Date: Fri, 21 Feb 2025 07:33:50 -0600 Subject: [PATCH 1/2] Added DialogueRunner as parameter to RunLine method Changed GenerateStringTable from internal to public Fixed Localization.GetLocalizedObjectSync if USE_ADDRESSABLES --- Editor/Importers/YarnProjectImporter.cs | 2 +- Runtime/DialogueRunner/DialogueRunner.cs | 2 +- Runtime/Localisation/Localization.cs | 5 +++-- Runtime/Views/DialoguePresenterBase.cs | 2 +- Runtime/Views/Legacy/DialogueViewBase.cs | 6 +++--- Runtime/Views/Legacy/LineView.cs | 2 +- Runtime/Views/Legacy/OptionsListView.cs | 2 +- Runtime/Views/LineAdvancer.cs | 2 +- Runtime/Views/LinePresenter.cs | 2 +- Runtime/Views/OptionsPresenter.cs | 2 +- Runtime/Views/VoiceOverPresenter.cs | 2 +- 11 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Editor/Importers/YarnProjectImporter.cs b/Editor/Importers/YarnProjectImporter.cs index e955daf5..84b2fcd9 100644 --- a/Editor/Importers/YarnProjectImporter.cs +++ b/Editor/Importers/YarnProjectImporter.cs @@ -1291,7 +1291,7 @@ internal IEnumerable GetErrorsForScript(TextAsset sourceScript) return Enumerable.Empty(); } - internal IEnumerable? GenerateStringsTable() + public IEnumerable? GenerateStringsTable() { var job = GetCompilationJob(); job.CompilationType = CompilationJob.Type.StringsOnly; diff --git a/Runtime/DialogueRunner/DialogueRunner.cs b/Runtime/DialogueRunner/DialogueRunner.cs index bcab3b94..ccd27029 100644 --- a/Runtime/DialogueRunner/DialogueRunner.cs +++ b/Runtime/DialogueRunner/DialogueRunner.cs @@ -663,7 +663,7 @@ async YarnTask RunLineAndInvokeCompletion(DialoguePresenterBase view, LocalizedL try { // Run the line and wait for it to finish - await view.RunLineAsync(localisedLine, token); + await view.RunLineAsync(this, localisedLine, token); } catch (System.Exception e) { diff --git a/Runtime/Localisation/Localization.cs b/Runtime/Localisation/Localization.cs index 4bf16339..cae4560c 100644 --- a/Runtime/Localisation/Localization.cs +++ b/Runtime/Localisation/Localization.cs @@ -195,7 +195,7 @@ public void AddLocalizedStrings(IEnumerable stringTableEntries return null; } -#endif +#else public YarnTask GetLocalizedObjectAsync(string key) where T : UnityEngine.Object { if (!entries.TryGetValue(key, out var entry)) @@ -210,6 +210,7 @@ public void AddLocalizedStrings(IEnumerable stringTableEntries return null; } +#endif #if UNITY_EDITOR internal T? GetLocalizedObjectSync(string key) where T : UnityEngine.Object @@ -277,7 +278,7 @@ public void AddLocalizedObjectToAsset(string key, T value) where T : UnityEng entry.localizedAsset = value; } #endif - #endregion +#endregion public virtual void Clear() { diff --git a/Runtime/Views/DialoguePresenterBase.cs b/Runtime/Views/DialoguePresenterBase.cs index 45189ad8..1aa694b2 100644 --- a/Runtime/Views/DialoguePresenterBase.cs +++ b/Runtime/Views/DialoguePresenterBase.cs @@ -78,7 +78,7 @@ public abstract class DialoguePresenterBase : MonoBehaviour /// showing the line to the user. /// - public abstract YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token); + public abstract YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token); /// diff --git a/Runtime/Views/Legacy/DialogueViewBase.cs b/Runtime/Views/Legacy/DialogueViewBase.cs index a8441c2b..2ed9da8c 100644 --- a/Runtime/Views/Legacy/DialogueViewBase.cs +++ b/Runtime/Views/Legacy/DialogueViewBase.cs @@ -119,7 +119,7 @@ public virtual void DialogueStarted() /// /// /// - public virtual void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) + public virtual void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished) { // The default implementation does nothing, and immediately calls // onDialogueLineFinished. @@ -367,7 +367,7 @@ public override YarnTask OnDialogueCompleteAsync() // This method implements the v3 async pattern for dialogue views on top // of the v2 API. /// - public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token) + public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token) { // phaseComplete is a flag that represents whether the current // 'phase' of a v2-style dialogue view (Run, Interrupt, Dismiss) is @@ -376,7 +376,7 @@ public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellation void PhaseComplete() => phaseComplete = true; // Run the line, and make phaseComplete become true when it's done. - this.RunLine(line, PhaseComplete); + this.RunLine(runner, line, PhaseComplete); // Wait for one of the following things to happen: // 1. RunLine completes successfully and calls PhaseComplete. diff --git a/Runtime/Views/Legacy/LineView.cs b/Runtime/Views/Legacy/LineView.cs index e5d44595..26cfd3e8 100644 --- a/Runtime/Views/Legacy/LineView.cs +++ b/Runtime/Views/Legacy/LineView.cs @@ -333,7 +333,7 @@ public override void InterruptLine(LocalizedLine dialogueLine, Action onInterrup } /// - public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) + public override void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished) { // Stop any coroutines currently running on this line view (for // example, any other RunLine that might be running) diff --git a/Runtime/Views/Legacy/OptionsListView.cs b/Runtime/Views/Legacy/OptionsListView.cs index a74a292c..43303ee0 100644 --- a/Runtime/Views/Legacy/OptionsListView.cs +++ b/Runtime/Views/Legacy/OptionsListView.cs @@ -55,7 +55,7 @@ public void Reset() canvasGroup = GetComponentInParent(); } - public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) + public override void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished) { // Don't do anything with this line except note it and immediately // indicate that we're finished with it. RunOptions will use it to diff --git a/Runtime/Views/LineAdvancer.cs b/Runtime/Views/LineAdvancer.cs index 5853cfa4..a9ea3ccb 100644 --- a/Runtime/Views/LineAdvancer.cs +++ b/Runtime/Views/LineAdvancer.cs @@ -297,7 +297,7 @@ public override YarnTask OnDialogueCompleteAsync() /// /// /// A completed task. - public override YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token) + public override YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token) { // A new line has come in, so reset the number of times we've seen a // request to skip. diff --git a/Runtime/Views/LinePresenter.cs b/Runtime/Views/LinePresenter.cs index 243568db..7c9c37dc 100644 --- a/Runtime/Views/LinePresenter.cs +++ b/Runtime/Views/LinePresenter.cs @@ -261,7 +261,7 @@ private void Start() /// Presents a line using the configured text view. /// /// - public override async YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token) + public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token) { if (lineText == null) { diff --git a/Runtime/Views/OptionsPresenter.cs b/Runtime/Views/OptionsPresenter.cs index 20d74c72..695b64e3 100644 --- a/Runtime/Views/OptionsPresenter.cs +++ b/Runtime/Views/OptionsPresenter.cs @@ -145,7 +145,7 @@ public override YarnTask OnDialogueStartedAsync() /// /// A completed task. - public override YarnTask RunLineAsync(LocalizedLine line, LineCancellationToken token) + public override YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, LineCancellationToken token) { if (showsLastLine) { diff --git a/Runtime/Views/VoiceOverPresenter.cs b/Runtime/Views/VoiceOverPresenter.cs index aaec0aec..aa994871 100644 --- a/Runtime/Views/VoiceOverPresenter.cs +++ b/Runtime/Views/VoiceOverPresenter.cs @@ -109,7 +109,7 @@ void Reset() /// LineCancellationToken)" path="/param"/> /// - public override async YarnTask RunLineAsync(LocalizedLine dialogueLine, LineCancellationToken lineCancellationToken) + public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine dialogueLine, LineCancellationToken lineCancellationToken) { // Get the localized voice over audio clip AudioClip? voiceOverClip = null; From 597d4874f19d2f1a8641456c0837b0e06bcf0927 Mon Sep 17 00:00:00 2001 From: "TITAN\\ckilg" Date: Fri, 21 Feb 2025 10:40:03 -0600 Subject: [PATCH 2/2] Added DialogueRunner as parameter for RunOptions, DismissLine, and InterruptLine --- Runtime/DialogueRunner/DialogueRunner.cs | 2 +- Runtime/Views/DialoguePresenterBase.cs | 2 +- Runtime/Views/Legacy/DialogueViewBase.cs | 14 +++++++------- Runtime/Views/Legacy/LineView.cs | 4 ++-- Runtime/Views/Legacy/OptionsListView.cs | 2 +- Runtime/Views/LineAdvancer.cs | 2 +- Runtime/Views/LinePresenter.cs | 2 +- Runtime/Views/OptionsPresenter.cs | 2 +- Runtime/Views/VoiceOverPresenter.cs | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Runtime/DialogueRunner/DialogueRunner.cs b/Runtime/DialogueRunner/DialogueRunner.cs index ccd27029..e54322d4 100644 --- a/Runtime/DialogueRunner/DialogueRunner.cs +++ b/Runtime/DialogueRunner/DialogueRunner.cs @@ -737,7 +737,7 @@ async YarnTask WaitForOptionsView(DialoguePresenterBase? view) { return; } - var result = await view.RunOptionsAsync(localisedOptions, optionCancellationSource.Token); + var result = await view.RunOptionsAsync(this, localisedOptions, optionCancellationSource.Token); if (result != null) { // We no longer need the other views, so tell them to stop diff --git a/Runtime/Views/DialoguePresenterBase.cs b/Runtime/Views/DialoguePresenterBase.cs index 1aa694b2..12c3d979 100644 --- a/Runtime/Views/DialoguePresenterBase.cs +++ b/Runtime/Views/DialoguePresenterBase.cs @@ -119,7 +119,7 @@ public abstract class DialoguePresenterBase : MonoBehaviour /// A task that indicates which option was selected, or that this dialogue view did not select an option. /// /// - public abstract YarnTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken); + public abstract YarnTask RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken); /// Called by the to signal that /// dialogue has started. diff --git a/Runtime/Views/Legacy/DialogueViewBase.cs b/Runtime/Views/Legacy/DialogueViewBase.cs index 2ed9da8c..9b8d855e 100644 --- a/Runtime/Views/Legacy/DialogueViewBase.cs +++ b/Runtime/Views/Legacy/DialogueViewBase.cs @@ -174,7 +174,7 @@ public virtual void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, A /// called after the line has finished being presented. /// /// - public virtual void InterruptLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) + public virtual void InterruptLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onDialogueLineFinished) { // the default implementation does nothing onDialogueLineFinished?.Invoke(); @@ -217,7 +217,7 @@ public virtual void InterruptLine(LocalizedLine dialogueLine, Action onDialogueL /// /// The method that should be called /// when the view has finished dismissing the line. - public virtual void DismissLine(Action onDismissalComplete) + public virtual void DismissLine(DialogueRunner runner, Action onDismissalComplete) { // The default implementation does nothing, and immediately calls // onDialogueLineFinished. @@ -272,7 +272,7 @@ public virtual void DismissLine(Action onDismissalComplete) /// displayed to the user. /// A method that should be called when /// the user has made a selection. - public virtual void RunOptions(DialogueOption[] dialogueOptions, Action onOptionSelected) + public virtual void RunOptions(DialogueRunner runner, DialogueOption[] dialogueOptions, Action onOptionSelected) { // The default implementation does nothing. } @@ -394,7 +394,7 @@ public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine if (token.IsNextLineRequested) { phaseComplete = false; - this.InterruptLine(line, PhaseComplete); + this.InterruptLine(runner, line, PhaseComplete); while (phaseComplete == false && Application.exitCancellationToken.IsCancellationRequested == false) { @@ -405,7 +405,7 @@ public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine // Finally, signal that the line should be dismissed, and wait for // the dismissal to complete. phaseComplete = false; - this.DismissLine(PhaseComplete); + this.DismissLine(runner, PhaseComplete); while (phaseComplete == false && Application.exitCancellationToken.IsCancellationRequested == false) @@ -417,13 +417,13 @@ public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine // This method implements the v3 async pattern for dialogue views on top // of the v2 API. /// - public override async YarnTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken) + public override async YarnTask RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken) { int selectedOptionID = -1; // Run the options, and wait for either a selection to be made, or // for this view to be cancelled. - this.RunOptions(dialogueOptions, (selectedID) => + this.RunOptions(runner, dialogueOptions, (selectedID) => { selectedOptionID = selectedID; }); diff --git a/Runtime/Views/Legacy/LineView.cs b/Runtime/Views/Legacy/LineView.cs index 26cfd3e8..cdd6b709 100644 --- a/Runtime/Views/Legacy/LineView.cs +++ b/Runtime/Views/Legacy/LineView.cs @@ -245,7 +245,7 @@ private void Reset() } /// - public override void DismissLine(Action onDismissalComplete) + public override void DismissLine(DialogueRunner runner, Action onDismissalComplete) { currentLine = null; @@ -278,7 +278,7 @@ private IEnumerator DismissLineInternal(Action onDismissalComplete) } /// - public override void InterruptLine(LocalizedLine dialogueLine, Action onInterruptLineFinished) + public override void InterruptLine(DialogueRunner runner, LocalizedLine dialogueLine, Action onInterruptLineFinished) { if (this == null) { diff --git a/Runtime/Views/Legacy/OptionsListView.cs b/Runtime/Views/Legacy/OptionsListView.cs index 43303ee0..01c0ff36 100644 --- a/Runtime/Views/Legacy/OptionsListView.cs +++ b/Runtime/Views/Legacy/OptionsListView.cs @@ -63,7 +63,7 @@ public override void RunLine(DialogueRunner runner, LocalizedLine dialogueLine, lastSeenLine = dialogueLine; onDialogueLineFinished(); } - public override void RunOptions(DialogueOption[] dialogueOptions, Action onOptionSelected) + public override void RunOptions(DialogueRunner runner, DialogueOption[] dialogueOptions, Action onOptionSelected) { // If we don't already have enough option views, create more while (dialogueOptions.Length > optionViews.Count) diff --git a/Runtime/Views/LineAdvancer.cs b/Runtime/Views/LineAdvancer.cs index a9ea3ccb..5e737cc2 100644 --- a/Runtime/Views/LineAdvancer.cs +++ b/Runtime/Views/LineAdvancer.cs @@ -321,7 +321,7 @@ public override YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, /// /// A completed task indicating that no option was selected by /// this view. - public override YarnTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken) + public override YarnTask RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken) { // This line view doesn't take any actions when options are // presented. diff --git a/Runtime/Views/LinePresenter.cs b/Runtime/Views/LinePresenter.cs index 7c9c37dc..be19c31c 100644 --- a/Runtime/Views/LinePresenter.cs +++ b/Runtime/Views/LinePresenter.cs @@ -405,7 +405,7 @@ public override async YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine /// /// This dialogue view does not handle any options. /// - public override YarnTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken) + public override YarnTask RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken) { return YarnTask.FromResult(null); } diff --git a/Runtime/Views/OptionsPresenter.cs b/Runtime/Views/OptionsPresenter.cs index 695b64e3..71f0ee9b 100644 --- a/Runtime/Views/OptionsPresenter.cs +++ b/Runtime/Views/OptionsPresenter.cs @@ -162,7 +162,7 @@ public override YarnTask RunLineAsync(DialogueRunner runner, LocalizedLine line, /// path="/param"/> /// - public override async YarnTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken) + public override async YarnTask RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken) { // If we don't already have enough option views, create more while (dialogueOptions.Length > optionViews.Count) diff --git a/Runtime/Views/VoiceOverPresenter.cs b/Runtime/Views/VoiceOverPresenter.cs index aa994871..5b4c8f21 100644 --- a/Runtime/Views/VoiceOverPresenter.cs +++ b/Runtime/Views/VoiceOverPresenter.cs @@ -240,7 +240,7 @@ public override YarnTask OnDialogueCompleteAsync() } /// - public override YarnTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken) + public override YarnTask RunOptionsAsync(DialogueRunner runner, DialogueOption[] dialogueOptions, CancellationToken cancellationToken) { return DialogueRunner.NoOptionSelected; }