MAJOR: Re-organize entire project
This commit is contained in:
13
Assets/Scripts/Dialogue/Dialogue.cs
Normal file
13
Assets/Scripts/Dialogue/Dialogue.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Dialogue
|
||||
{
|
||||
public string name;
|
||||
|
||||
[TextArea(3, 10)]
|
||||
public string[] sentences;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Dialogue/Dialogue.cs.meta
Normal file
11
Assets/Scripts/Dialogue/Dialogue.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef49f73d158f1f645a3a912266e9014e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Dialogue/Dialogue.meta
Normal file
8
Assets/Scripts/Dialogue/Dialogue.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcdc358652295014e9f9d90638ab5d0d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Dialogue/DialogueManager.cs.meta
Normal file
11
Assets/Scripts/Dialogue/DialogueManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25e10eb1479a50a478ccc4cd14c6269b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/Dialogue/DialogueTrigger.cs
Normal file
14
Assets/Scripts/Dialogue/DialogueTrigger.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam
|
||||
{
|
||||
public class DialogueTrigger : MonoBehaviour
|
||||
{
|
||||
public Dialogue dialogue;
|
||||
|
||||
public void TriggerDialogue()
|
||||
{
|
||||
DialogueManager.Instance.StartDialogue(dialogue);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Dialogue/DialogueTrigger.cs.meta
Normal file
11
Assets/Scripts/Dialogue/DialogueTrigger.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 395173c319b902c4fafc1c6c0d433f24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user