using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; [Serializable] public class DialogueController { public Queue listOfDialogue = new Queue(); private UnityEvent EndOfDialogueStepAction = new UnityEvent(); [SerializeField] public GameObject CurrentPanel; /// /// Set panel info (panel, coords, text, buttons) /// /// public void AddSentence(DialogueModel dialogueModel) { listOfDialogue.Enqueue(dialogueModel); } /* * TODO add endpoints to setup button sctions via others scripyts ! ! ! public void AddButton(PanelButtonStepModel _buttonModel) { Buttons.Add(_buttonModel); } public void SetButtons(List _buttonsModelList) { Buttons = _buttonsModelList; } */ public void SetActionAfterDialogueEnds(UnityEvent _endOfDialogueStepAction) { EndOfDialogueStepAction = _endOfDialogueStepAction; } public void SetActionAfterDialogueEnds(Action _finishDialogueAction) { EndOfDialogueStepAction.AddListener( new UnityAction( _finishDialogueAction)); } public void Show(DialogueModel panelModel) { Panel panelDis = panelModel.Panel("Kabix", panelModel); panelDis.PanelInstance = panelDis.BuildPanel(); panelDis.SetContinueButtonAction(ShowNextPanel, this); CurrentPanel = panelDis.PanelInstance; } private void ShowNextPanel(DialogueController parentDialController) { if (listOfDialogue.Count == 0) { MonoBehaviour.Destroy(parentDialController.CurrentPanel); FinishDialogue(); } else { MonoBehaviour.Destroy(parentDialController.CurrentPanel); DialogueModel nextPanel = parentDialController.listOfDialogue.Dequeue(); Show(nextPanel); } } // if palyer click last dialogue panel's "continue" button then ShowNextPanel // function invoke this method whioch contain external action :D - MAGIC public void FinishDialogue() { // set uoe everything whats is needed to change after finish dialogue // eg. // - add task to list // - get reward // - mark quest as completed :D EndOfDialogueStepAction.Invoke(); } }