From cc9c34930fb127208013c205d9ce15c5e5df622f Mon Sep 17 00:00:00 2001 From: kabix09 Date: Tue, 6 Dec 2022 21:35:17 +0100 Subject: [PATCH] Fix - dialogue structure --- Assets/Resources/Dialogue/BossThug.meta | 8 + Assets/Resources/Dialogue/BossThug/PL.meta | 8 + .../Dialogue/BossThug/PL/BossThugDialPl.asset | 39 +++++ .../BossThug/PL/BossThugDialPl.asset.meta | 8 + .../BossThug/PL/BossThugMultiDialPl.asset | 19 ++ .../PL/BossThugMultiDialPl.asset.meta | 8 + .../Resources/Dialogue/BossThugDialPl.asset | 28 +-- .../SampleScene/Enemies/BossThug.prefab | 2 +- .../Scripts/Enemies' Scprits/Cave/BossThug.cs | 2 +- .../Application/Dialogue/Controller.meta | 8 + .../{ => Controller}/DialogueController.cs | 0 .../DialogueController.cs.meta | 0 .../Application/Dialogue/Dialogue.cs | 135 +++----------- .../Application/Dialogue/Dialogue.cs.meta | 2 +- .../Application/Dialogue/IDialogue.cs | 19 ++ .../Application/Dialogue/IDialogue.cs.meta | 11 ++ .../Application/Dialogue/MultiDialogue.cs | 164 ++++++++++++++++++ .../Dialogue/MultiDialogue.cs.meta | 11 ++ .../Application/NPC/NpcDialogueManager.cs | 6 +- 19 files changed, 335 insertions(+), 143 deletions(-) create mode 100644 Assets/Resources/Dialogue/BossThug.meta create mode 100644 Assets/Resources/Dialogue/BossThug/PL.meta create mode 100644 Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset create mode 100644 Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset.meta create mode 100644 Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset create mode 100644 Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/Controller.meta rename Assets/Scripts/REFACTORING/Application/Dialogue/{ => Controller}/DialogueController.cs (100%) rename Assets/Scripts/REFACTORING/Application/Dialogue/{ => Controller}/DialogueController.cs.meta (100%) create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs.meta create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs create mode 100644 Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs.meta diff --git a/Assets/Resources/Dialogue/BossThug.meta b/Assets/Resources/Dialogue/BossThug.meta new file mode 100644 index 00000000..1df8e6af --- /dev/null +++ b/Assets/Resources/Dialogue/BossThug.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d9fa006e9c23c6b48bad6eb4312ffb9a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Dialogue/BossThug/PL.meta b/Assets/Resources/Dialogue/BossThug/PL.meta new file mode 100644 index 00000000..5546c7a3 --- /dev/null +++ b/Assets/Resources/Dialogue/BossThug/PL.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 746d0ce278aa8bf4b980ee3b69386d72 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset b/Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset new file mode 100644 index 00000000..46c95c85 --- /dev/null +++ b/Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset @@ -0,0 +1,39 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 06201cadd951bcc4db5fccaa01783060, type: 3} + m_Name: BossThugDialPl + m_EditorClassIdentifier: + SpeakerName: + CurrentStep: 0 + DialogueSteps: + - Header: + WasDisplayed: 0 + ListOfSentences: + - Sentence: Who are you? How did you get past my guards?! + Buttons: [] + - Sentence: Don't answer, I don't care anyway. You're dead to me. + Buttons: [] + EndOfDialogueStepAction: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 4267060477434669900, guid: df6c42c9616028a4badca81953f003ab, type: 3} + m_TargetAssemblyTypeName: NpcDialogueManager, Assembly-CSharp + m_MethodName: DialogueEndAction + m_Mode: 3 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 diff --git a/Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset.meta b/Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset.meta new file mode 100644 index 00000000..f84beee9 --- /dev/null +++ b/Assets/Resources/Dialogue/BossThug/PL/BossThugDialPl.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ccce026cbe2eff3478d588341e4dd531 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset b/Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset new file mode 100644 index 00000000..278e691a --- /dev/null +++ b/Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset @@ -0,0 +1,19 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 45b41589283138641ba006c2243b0637, type: 3} + m_Name: BossThugMultiDialPl + m_EditorClassIdentifier: + SpeakerName: + CurrentDialogue: 0 + Dialogues: + - Key: 0 + Value: {fileID: 11400000, guid: ccce026cbe2eff3478d588341e4dd531, type: 2} diff --git a/Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset.meta b/Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset.meta new file mode 100644 index 00000000..45a7a27c --- /dev/null +++ b/Assets/Resources/Dialogue/BossThug/PL/BossThugMultiDialPl.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cb19cd4601a7b9f4c8804f5ec09ad157 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Dialogue/BossThugDialPl.asset b/Assets/Resources/Dialogue/BossThugDialPl.asset index ea816197..e57abbfc 100644 --- a/Assets/Resources/Dialogue/BossThugDialPl.asset +++ b/Assets/Resources/Dialogue/BossThugDialPl.asset @@ -14,30 +14,6 @@ MonoBehaviour: m_EditorClassIdentifier: SpeakerName: CurrentDialogue: 0 - MultiWayDialogue: + Dialogues: - Key: 0 - Value: - - Header: - WasDisplayed: 0 - ListOfSentences: - - Header: - Sentence: Who are you? Hod did you get past my guards?! - Buttons: [] - - Header: - Sentence: Don't answer. I don't care anyway. You're dead to me/. - Buttons: [] - EndOfDialogueStepAction: - m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 4267060477434669900, guid: df6c42c9616028a4badca81953f003ab, type: 3} - m_TargetAssemblyTypeName: NpcDialogueManager, Assembly-CSharp - m_MethodName: DialogueEndAction - m_Mode: 3 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + Value: {fileID: 0} diff --git a/Assets/Resources/SampleScene/Enemies/BossThug.prefab b/Assets/Resources/SampleScene/Enemies/BossThug.prefab index d0f6bb6b..63a16389 100644 --- a/Assets/Resources/SampleScene/Enemies/BossThug.prefab +++ b/Assets/Resources/SampleScene/Enemies/BossThug.prefab @@ -168,7 +168,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: SpeakerName: Thug Boss - DialogueTemplate: {fileID: 11400000, guid: b47b2441f5e5f9e4ab687bf2a2fddbfa, type: 2} + DialogueTemplate: {fileID: 11400000, guid: cb19cd4601a7b9f4c8804f5ec09ad157, type: 2} Dialogue: {fileID: 0} EndactionEventList: - Key: diff --git a/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs b/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs index 3df4c656..1edc9c09 100644 --- a/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs +++ b/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs @@ -135,7 +135,7 @@ public class BossThug : MonoBehaviour isDuringConversation = false; - gameObject.GetComponent().Dialogue.BreakDialogue(); + gameObject.GetComponent().Dialogue.BreakDialogueStep(); //TODO break dialogue after leaving collider range!!! } diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Controller.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Controller.meta new file mode 100644 index 00000000..b148d649 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Controller.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d8a9f0c703509b94a93e318c01cf0ef6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/DialogueController.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Controller/DialogueController.cs similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Dialogue/DialogueController.cs rename to Assets/Scripts/REFACTORING/Application/Dialogue/Controller/DialogueController.cs diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/DialogueController.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Controller/DialogueController.cs.meta similarity index 100% rename from Assets/Scripts/REFACTORING/Application/Dialogue/DialogueController.cs.meta rename to Assets/Scripts/REFACTORING/Application/Dialogue/Controller/DialogueController.cs.meta diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs index ee295556..36af7296 100644 --- a/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs @@ -1,71 +1,41 @@ using System; using System.Collections.Generic; -using System.Linq; +using UnityEditor; using UnityEngine; + [Serializable] [CreateAssetMenu(fileName = "New Dialogue", menuName = "Dialogue/New Dialogue")] -public class Dialogue : ScriptableObject +public class Dialogue : ScriptableObject, IDialogue { [SerializeField] public string SpeakerName; [SerializeField] - int CurrentDialogue = 0; + int CurrentStep = 0; [SerializeField] - public List>> MultiWayDialogue; + public List DialogueSteps; - - /* - Dialogues - list of dialoges - Steps bucket (one dialogue unit) - list of liner 'steps', finished special action, whole can be stopped special requirements (like go and do something - to declared in 'finish action') - Steps - its a cell package contains 'sentences' (one per panel) - Sentence - its a opanel with phrase and buttons - */ - - /* - * WAZNE: - * Jesli przechodzimy odpowiedzia do nastepnego dialogu musi to byc osttani panel w obecnym!!! - */ - - public void Start() + public void SetSpeakerName(string speakerName) { - /* CODE DIALOGUE DECLARATION EXAMPLE + SpeakerName = speakerName; - DialogueController DialogueStep = new DialogueController(); - DialogueStep.AddSentence(new DialogueModel("lorem ipsum")); - *//* di.AddSentence(new QuestionDialogueModel("tolore dolore?", - new List> { - new Tuple("AcceptButton", CustomPanel), - new Tuple("RejectButton", QuestionPanel) - }));*//* - DialogueStep.SetActionAfterDialogueEnds(() => { }); - - DialogueStepModel dialogueStepModel = new DialogueStepModel(DialogueStep); - - DialogueStepsList = new List { dialogueStepModel }; - */ - /*if (MultiWayDialogue.Count > 0) - BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);*/ + DialogueSteps.ForEach(step => step.Header = speakerName); } public void StartDialogue() { // 1. Build - BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value); + BuildDialogue(DialogueSteps); // 2. Show first step - ShowStep(); + ShowDialogueStepPanel(); } - public void BreakDialogue() + public void BreakDialogueStep() { - // 1. Find first yet undisplayed for player anbd show - - var dialogueStepsList = MultiWayDialogue.Where(el => el.Key == CurrentDialogue).ToArray().First().Value; - - foreach (var DialogueStep in dialogueStepsList) + foreach (var DialogueStep in DialogueSteps) { if (!DialogueStep.WasDisplayed && DialogueStep.DialogueController.CurrentPanel != null) { @@ -84,13 +54,9 @@ public class Dialogue : ScriptableObject /// /// The best way is to invoked its after player reaction from other script (by event - collision) :) /// - public void ShowStep() + public void ShowDialogueStepPanel() { - // 1. Find first yet undisplayed for player anbd show - - var dialogueStepsList = MultiWayDialogue.Where(el => el.Key == CurrentDialogue).ToArray().First().Value; - - foreach (var DialogueStep in dialogueStepsList) + foreach (var DialogueStep in DialogueSteps) { if (!DialogueStep.WasDisplayed && DialogueStep.DialogueController.listOfDialogue.Count != 0) { @@ -104,7 +70,12 @@ public class Dialogue : ScriptableObject /// /// Dialogue API /// - /// Default function to get next sentence if dialogue is currently started + /// Function to automaticly go to next dialgue sentence (in this or next step eg after pressing button on panel + /// It provide that dialogue not braking after finishing current step + /// + /// The dialogue follows the order of the lists ! ! + /// + /// It's default function to get next sentence if dialogue is currently started /// It is responsible for detecting /// 1) if there is any dialogue panel already created before displaying next sentence /// 2) if its last panel sentence and invoiking 'end dialogue' action @@ -113,11 +84,7 @@ public class Dialogue : ScriptableObject /// public void GoToNextSentence() { - // 1. Find first yet undisplayed for player anbd show - - var dialogueStepsList = MultiWayDialogue.Where(el => el.Key == CurrentDialogue).ToArray().First().Value; - - foreach (var DialogueStep in dialogueStepsList) + foreach (var DialogueStep in DialogueSteps) { if (!DialogueStep.WasDisplayed) { @@ -127,7 +94,7 @@ public class Dialogue : ScriptableObject { DialogueStep.WasDisplayed = true; - ShowStep(); + ShowDialogueStepPanel(); } break; @@ -136,49 +103,9 @@ public class Dialogue : ScriptableObject } /// - /// Dialogue API - /// - /// Function to prepare next dialogue to start after one more palyer interaction with actor - /// - ends current dialogue (destroy panel & invoke finish action - if setupped) - /// - set new dialogue pointer - /// + /// Function to build each step of dialogue /// - /// - public void SetNextDialogue(int dialogueNumber) - { - if (MultiWayDialogue.Where(el => el.Key == dialogueNumber).ToArray().Count() == 0) - return; - - // 1. Make sure to close current panel after finishing current dialogue and 'finish action' will invoked if setuped - GoToNextSentence(); - - // 2. Chane index - CurrentDialogue = dialogueNumber; - } - - /// - /// Dialogue API - /// - /// Function to finish current dialog and immediately start next one - /// - /// - /// - public void GoToNextDialogue(int dialogueNumber) - { - // 1. Prepare necessary environoment parts - SetNextDialogue(dialogueNumber); - - // 3. Build new dialogue - BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value); - - // 4. Start new dialogue bucket - ShowStep(); - } - - /// - /// Build each step of dialogue - /// - private void BuildDialogue(List Dialogue) + public void BuildDialogue(List Dialogue) { foreach (var dialogueStep in Dialogue) { @@ -187,18 +114,4 @@ public class Dialogue : ScriptableObject dialogueStep.Build(); } } - - public (int, int) DialogueStepStatus() - { - var currentDialogueStepIndex = MultiWayDialogue - .Where(el => el.Key == CurrentDialogue) - .Select(el => el.Value) - .First() - .Where(step => step.WasDisplayed == true) - .ToArray() - .Count() - ; - - return(CurrentDialogue, currentDialogueStepIndex); - } } diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs.meta index 7e7cfe65..00e71d21 100644 --- a/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs.meta +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/Dialogue.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 45b41589283138641ba006c2243b0637 +guid: 06201cadd951bcc4db5fccaa01783060 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs new file mode 100644 index 00000000..1cbde962 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + + +public interface IDialogue +{ + public void SetSpeakerName(string speakerName); + + public void StartDialogue(); + + public void BreakDialogueStep(); + + public void ShowDialogueStepPanel(); + + public void GoToNextSentence(); + + public void BuildDialogue(List Dialogue); +} diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs.meta new file mode 100644 index 00000000..bf9ceaf9 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/IDialogue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 98a40f30fd98e1443aa1034fcfcaadc4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs b/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs new file mode 100644 index 00000000..e212d0c0 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +[Serializable] +[CreateAssetMenu(fileName = "New Dialogue", menuName = "Dialogue/New Multi Dialogue")] +public class MultiDialogue : ScriptableObject, IDialogue +{ + [SerializeField] + public string SpeakerName; + + [SerializeField] + int CurrentDialogue = 0; + + [SerializeField] + public List> Dialogues; + + + /* + Dialogues - list of dialoges + Steps bucket (one dialogue unit) - list of liner 'steps', finished special action, whole can be stopped special requirements (like go and do something - to declared in 'finish action') + Steps - its a cell package contains 'sentences' (one per panel) + Sentence - its a opanel with phrase and buttons + */ + + /* + * WAZNE: + * Jesli przechodzimy odpowiedzia do nastepnego dialogu musi to byc osttani panel w obecnym!!! + */ + + public void Start() + { + /* CODE DIALOGUE DECLARATION EXAMPLE + + DialogueController DialogueStep = new DialogueController(); + DialogueStep.AddSentence(new DialogueModel("lorem ipsum")); + *//* di.AddSentence(new QuestionDialogueModel("tolore dolore?", + new List> { + new Tuple("AcceptButton", CustomPanel), + new Tuple("RejectButton", QuestionPanel) + }));*//* + DialogueStep.SetActionAfterDialogueEnds(() => { }); + + DialogueStepModel dialogueStepModel = new DialogueStepModel(DialogueStep); + + DialogueStepsList = new List { dialogueStepModel }; + */ + /*if (MultiWayDialogue.Count > 0) + BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);*/ + } + + public void SetSpeakerName(string speakerName) + { + SpeakerName = speakerName; + + Dialogues.ForEach(dialogue => dialogue.Value.SetSpeakerName(speakerName)); + } + + public void StartDialogue() + { + // 1. Start Dialogue (build + show panel) + Dialogues.Where(el => el.Key == CurrentDialogue).First().Value.StartDialogue(); + } + + public void BreakDialogueStep() + { + // 1. Break Dialogue (close panel without marking as displayed) + Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.BreakDialogueStep(); + } + + /// + /// Dialogue API + /// + /// MAIN bunction to begin dialogue + /// Create new panel instance on scene by force with sentence from queue + /// + /// The best way is to invoked its after player reaction from other script (by event - collision) :) + /// + public void ShowDialogueStepPanel() + { + Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.ShowDialogueStepPanel(); + } + + /// + /// Dialogue API + /// + /// Default function to get next sentence if dialogue is currently started + /// It is responsible for detecting + /// 1) if there is any dialogue panel already created before displaying next sentence + /// 2) if its last panel sentence and invoiking 'end dialogue' action + /// + /// Whats more, if there was no more sentences in 'step', althroughr closing panel go to next step automatiiccally + /// + public void GoToNextSentence() + { + Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.GoToNextSentence(); + } + + /// + /// Dialogue API + /// + /// Function to prepare next dialogue to start after one more palyer interaction with actor + /// - ends current dialogue (destroy panel & invoke finish action - if setupped) + /// - set new dialogue pointer + /// + /// + /// + public void SetNextDialogue(int dialogueNumber) + { + if (Dialogues.Where(el => el.Key == dialogueNumber).ToArray().Count() == 0) + return; + + // 1. Make sure to close current panel after finishing current dialogue and 'finish action' will invoked if setuped + GoToNextSentence(); + + // 2. Chane index + CurrentDialogue = dialogueNumber; + } + + /// + /// Dialogue API + /// + /// Function to finish current dialog and immediately start next one + /// + /// + /// + public void GoToNextDialogue(int dialogueNumber) + { + // 1. Prepare necessary environoment parts + SetNextDialogue(dialogueNumber); + + // 2. Build new (next) dialogue & show panel + StartDialogue(); + } + + /// + /// Build each step of dialogue + /// + public void BuildDialogue(List Dialogue) + { + foreach (var dialogueStep in Dialogue) + { + dialogueStep.Header = SpeakerName; + + dialogueStep.Build(); + } + } + + public (int, int) DialogueStepStatus() + { + var currentDialogueStepIndex = Dialogues + .Where(el => el.Key == CurrentDialogue) + .Select(el => el.Value) + .First() + .DialogueSteps + .Where(step => step.WasDisplayed == true) + .ToArray() + .Count() + ; + + return(CurrentDialogue, currentDialogueStepIndex); + } +} diff --git a/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs.meta b/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs.meta new file mode 100644 index 00000000..7e7cfe65 --- /dev/null +++ b/Assets/Scripts/REFACTORING/Application/Dialogue/MultiDialogue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45b41589283138641ba006c2243b0637 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs b/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs index 5275e5fa..38c713ae 100644 --- a/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs +++ b/Assets/Scripts/REFACTORING/Application/NPC/NpcDialogueManager.cs @@ -12,11 +12,11 @@ public class NpcDialogueManager : MonoBehaviour public string SpeakerName; [SerializeField] - public Dialogue DialogueTemplate; + public MultiDialogue DialogueTemplate; /* We user object CLONED TO PREVENT overwritting changes in main object inassets */ [SerializeField] - public Dialogue Dialogue; + public MultiDialogue Dialogue; // List, Value : UnityEvent> public List, UnityEvent>> EndactionEventList; @@ -24,7 +24,7 @@ public class NpcDialogueManager : MonoBehaviour public void Start() { Dialogue = Instantiate(DialogueTemplate); - Dialogue.SpeakerName = SpeakerName; + Dialogue.SetSpeakerName(SpeakerName); } public void Update() { }