MAJOR: Re-organize entire project
This commit is contained in:
70
Assets/Scripts/Dialogue/DialogueManager.cs
Normal file
70
Assets/Scripts/Dialogue/DialogueManager.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
public class DialogueManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI nameText;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI dialogueText;
|
||||
public float TextSpeed = 0.1f;
|
||||
|
||||
public static DialogueManager Instance { get; private set; }
|
||||
|
||||
public Queue<string> sentences;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
sentences = new Queue<string>();
|
||||
}
|
||||
|
||||
public void StartDialogue(Dialogue dialogue)
|
||||
{
|
||||
nameText.text = dialogue.name;
|
||||
|
||||
sentences.Clear();
|
||||
foreach (var sentence in dialogue.sentences)
|
||||
sentences.Enqueue(sentence);
|
||||
|
||||
DisplayNextSentence();
|
||||
}
|
||||
|
||||
public void DisplayNextSentence()
|
||||
{
|
||||
if (!sentences.Any())
|
||||
EndDialogue();
|
||||
|
||||
var sentence = sentences.Dequeue();
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(TypeSentence(sentence));
|
||||
}
|
||||
|
||||
private IEnumerator TypeSentence(string sentence)
|
||||
{
|
||||
|
||||
dialogueText.text = string.Empty;
|
||||
foreach (var letter in sentence.ToCharArray())
|
||||
{
|
||||
dialogueText.text += letter;
|
||||
yield return null;
|
||||
yield return new WaitForSecondsRealtime(TextSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
private void EndDialogue()
|
||||
{
|
||||
// do nothing currently
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user