Implement dialogue system
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Scampz.GameJam.Assets.Scripts;
|
||||
using Scampz.GameJam.Assets.Scripts.Utilities;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,27 +10,28 @@ namespace Scampz.GameJam
|
||||
{
|
||||
public class DialogueManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator _animator;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI dialogueTextGUI;
|
||||
public float TextSpeed = 0.1f;
|
||||
[SerializeField]
|
||||
private float _textSpeed = 0.1f;
|
||||
|
||||
public Queue<string> sentences;
|
||||
private Queue<string> sentences;
|
||||
|
||||
private static DialogueManager _instance;
|
||||
public static DialogueManager Instance;
|
||||
|
||||
public static DialogueManager Instance
|
||||
public bool IsTalking = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
get
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
if (!_instance)
|
||||
{
|
||||
_instance = new GameObject().AddComponent<DialogueManager>();
|
||||
_instance.name = _instance.GetType().ToString();
|
||||
DontDestroyOnLoad(_instance.gameObject);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -36,8 +39,16 @@ namespace Scampz.GameJam
|
||||
sentences = new Queue<string>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (IsTalking && Input.GetButtonDown(InputOptions.Cancel))
|
||||
EndDialogue();
|
||||
}
|
||||
|
||||
public void StartDialogue(Dialogue dialogue)
|
||||
{
|
||||
_animator.SetBool("IsOpen", true);
|
||||
IsTalking = true;
|
||||
sentences.Clear();
|
||||
foreach (var sentence in dialogue.sentences)
|
||||
sentences.Enqueue(sentence);
|
||||
@@ -48,7 +59,10 @@ namespace Scampz.GameJam
|
||||
public void DisplayNextSentence()
|
||||
{
|
||||
if (!sentences.Any())
|
||||
{
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
var sentence = sentences.Dequeue();
|
||||
StopAllCoroutines();
|
||||
@@ -63,13 +77,17 @@ namespace Scampz.GameJam
|
||||
{
|
||||
dialogueTextGUI.text += letter;
|
||||
yield return null;
|
||||
yield return new WaitForSecondsRealtime(TextSpeed);
|
||||
yield return new WaitForSecondsRealtime(_textSpeed);
|
||||
}
|
||||
|
||||
yield return new WaitForKeyDown(InputOptions.Submit);
|
||||
DisplayNextSentence();
|
||||
}
|
||||
|
||||
private void EndDialogue()
|
||||
{
|
||||
// do nothing currently
|
||||
_animator.SetBool("IsOpen", false);
|
||||
IsTalking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user