2022-12-04 18:42:34 +01:00
|
|
|
|
using System;
|
2022-10-16 19:40:44 +02:00
|
|
|
|
using System.Collections.Generic;
|
2022-12-06 21:35:17 +01:00
|
|
|
|
using UnityEditor;
|
2022-10-16 19:40:44 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-12-06 21:35:17 +01:00
|
|
|
|
|
2022-10-16 19:40:44 +02:00
|
|
|
|
[Serializable]
|
2022-12-04 18:42:34 +01:00
|
|
|
|
[CreateAssetMenu(fileName = "New Dialogue", menuName = "Dialogue/New Dialogue")]
|
2022-12-06 21:35:17 +01:00
|
|
|
|
public class Dialogue : ScriptableObject, IDialogue
|
2022-10-16 19:40:44 +02:00
|
|
|
|
{
|
2022-12-06 03:10:36 +01:00
|
|
|
|
[SerializeField]
|
|
|
|
|
public string SpeakerName;
|
|
|
|
|
|
2022-12-02 02:11:37 +01:00
|
|
|
|
[SerializeField]
|
2022-12-06 21:35:17 +01:00
|
|
|
|
int CurrentStep = 0;
|
2022-12-02 02:11:37 +01:00
|
|
|
|
|
|
|
|
|
[SerializeField]
|
2022-12-06 21:35:17 +01:00
|
|
|
|
public List<DialogueStepModel> DialogueSteps;
|
2022-12-02 02:11:37 +01:00
|
|
|
|
|
2022-12-06 21:35:17 +01:00
|
|
|
|
public void SetSpeakerName(string speakerName)
|
2022-10-16 19:40:44 +02:00
|
|
|
|
{
|
2022-12-06 21:35:17 +01:00
|
|
|
|
SpeakerName = speakerName;
|
|
|
|
|
|
|
|
|
|
DialogueSteps.ForEach(step => step.Header = speakerName);
|
2022-12-02 02:11:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartDialogue()
|
|
|
|
|
{
|
|
|
|
|
// 1. Build
|
2022-12-06 21:35:17 +01:00
|
|
|
|
BuildDialogue(DialogueSteps);
|
2022-12-02 02:11:37 +01:00
|
|
|
|
|
|
|
|
|
// 2. Show first step
|
2022-12-06 21:35:17 +01:00
|
|
|
|
ShowDialogueStepPanel();
|
2022-12-02 02:11:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 21:35:17 +01:00
|
|
|
|
public void BreakDialogueStep()
|
2022-12-02 02:11:37 +01:00
|
|
|
|
{
|
2022-12-06 21:35:17 +01:00
|
|
|
|
foreach (var DialogueStep in DialogueSteps)
|
2022-12-02 02:11:37 +01:00
|
|
|
|
{
|
2022-12-06 03:10:36 +01:00
|
|
|
|
if (!DialogueStep.WasDisplayed && DialogueStep.DialogueController.CurrentPanel != null)
|
2022-12-02 02:11:37 +01:00
|
|
|
|
{
|
|
|
|
|
DialogueStep.DialogueController.CloseCurrentPanel(); // close panel
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-16 19:40:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-12-02 02:11:37 +01:00
|
|
|
|
/// 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) :)
|
2022-10-16 19:40:44 +02:00
|
|
|
|
/// </summary>
|
2022-12-06 21:35:17 +01:00
|
|
|
|
public void ShowDialogueStepPanel()
|
2022-10-16 19:40:44 +02:00
|
|
|
|
{
|
2022-12-06 21:35:17 +01:00
|
|
|
|
foreach (var DialogueStep in DialogueSteps)
|
2022-10-16 19:40:44 +02:00
|
|
|
|
{
|
2022-12-04 18:42:34 +01:00
|
|
|
|
if (!DialogueStep.WasDisplayed && DialogueStep.DialogueController.listOfDialogue.Count != 0)
|
2022-10-16 19:40:44 +02:00
|
|
|
|
{
|
2022-12-02 02:11:37 +01:00
|
|
|
|
DialogueStep.DialogueController.Show(DialogueStep.DialogueController.listOfDialogue.Dequeue()); // create panel
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dialogue API
|
|
|
|
|
///
|
2022-12-06 21:35:17 +01:00
|
|
|
|
/// 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
|
2022-12-02 02:11:37 +01:00
|
|
|
|
/// 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
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void GoToNextSentence()
|
|
|
|
|
{
|
2022-12-06 21:35:17 +01:00
|
|
|
|
foreach (var DialogueStep in DialogueSteps)
|
2022-12-02 02:11:37 +01:00
|
|
|
|
{
|
|
|
|
|
if (!DialogueStep.WasDisplayed)
|
|
|
|
|
{
|
|
|
|
|
var nextSentence = DialogueStep.DialogueController.ShowNextPanel(DialogueStep.DialogueController);
|
|
|
|
|
|
|
|
|
|
if (!nextSentence)
|
|
|
|
|
{
|
|
|
|
|
DialogueStep.WasDisplayed = true;
|
|
|
|
|
|
2022-12-06 21:35:17 +01:00
|
|
|
|
ShowDialogueStepPanel();
|
2022-12-02 02:11:37 +01:00
|
|
|
|
}
|
2022-10-16 19:40:44 +02:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 02:11:37 +01:00
|
|
|
|
/// <summary>
|
2022-12-06 21:35:17 +01:00
|
|
|
|
/// Function to build each step of dialogue
|
2022-12-02 02:11:37 +01:00
|
|
|
|
/// </summary>
|
2022-12-06 21:35:17 +01:00
|
|
|
|
public void BuildDialogue(List<DialogueStepModel> Dialogue)
|
2022-12-02 02:11:37 +01:00
|
|
|
|
{
|
|
|
|
|
foreach (var dialogueStep in Dialogue)
|
|
|
|
|
{
|
2022-12-06 03:10:36 +01:00
|
|
|
|
dialogueStep.Header = SpeakerName;
|
|
|
|
|
|
2022-12-02 02:11:37 +01:00
|
|
|
|
dialogueStep.Build();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-04 18:42:34 +01:00
|
|
|
|
}
|