init
This commit is contained in:
commit
341a877b4a
2338 changed files with 1346408 additions and 0 deletions
10
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs
Normal file
10
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Character", menuName = "Character")]
|
||||
public class Dialogue : ScriptableObject{
|
||||
|
||||
public string characterName;
|
||||
[TextArea] public string[] sentences;
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/Dialogue.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd553cd05b84d614b998afe62e37c17c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
44
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs
Normal file
44
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueSystem : MonoBehaviour{
|
||||
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI dialogueText;
|
||||
public TMP_Animated dialogue;
|
||||
|
||||
public Queue<string> sentences;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
sentences = new Queue<string>();
|
||||
}
|
||||
|
||||
public void StartDialogue(Dialogue dialogue){
|
||||
nameText.text = dialogue.characterName;
|
||||
|
||||
sentences.Clear();
|
||||
|
||||
foreach(string sentence in dialogue.sentences){
|
||||
sentences.Enqueue(sentence);
|
||||
}
|
||||
|
||||
DisplayNextSentence();
|
||||
}
|
||||
|
||||
public void DisplayNextSentence(){
|
||||
if(sentences.Count == 0){
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
string sentence = sentences.Dequeue();
|
||||
dialogue.ReadText(sentence);
|
||||
}
|
||||
|
||||
void EndDialogue(){
|
||||
Debug.Log("End of conversation.");
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/DialogueSystem.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: caad12703fd5c3349acc637253734ac9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs
Normal file
13
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueTrigger : MonoBehaviour{
|
||||
|
||||
public Dialogue dialogue;
|
||||
|
||||
/// <summary> Start the dialogue specified on the inspector </summary>
|
||||
public void TriggerDialogue(){
|
||||
FindObjectOfType<DialogueSystem>().StartDialogue(dialogue);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/DialogueTrigger.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f15c572386779eb4aa5d6e8471fba51d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs
Normal file
76
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace TMPro{
|
||||
[System.Serializable] public class TextRevealEvent : UnityEvent<char> { }
|
||||
[System.Serializable] public class DialogueEvent : UnityEvent { }
|
||||
|
||||
public class TMP_Animated : TextMeshProUGUI{
|
||||
|
||||
float speed;
|
||||
|
||||
public TextRevealEvent onTextReveal;
|
||||
public DialogueEvent onDialogueFinish;
|
||||
|
||||
public void ClearText(){
|
||||
text = string.Empty;
|
||||
}
|
||||
|
||||
public void ReadText(string newText){
|
||||
text = string.Empty;
|
||||
|
||||
string[] subTexts = newText.Split('<', '>');
|
||||
|
||||
string displayText = "";
|
||||
for (int i = 0; i < subTexts.Length; i++){
|
||||
if (i % 2 == 0)
|
||||
displayText += subTexts[i];
|
||||
else if (!isCustomTag(subTexts[i].Replace(" ", "")))
|
||||
displayText += $"<{subTexts[i]}>";
|
||||
}
|
||||
|
||||
bool isCustomTag(string tag){
|
||||
return tag.StartsWith("speed=") || tag.StartsWith("pause=");
|
||||
}
|
||||
|
||||
text = displayText;
|
||||
maxVisibleCharacters = 0;
|
||||
StartCoroutine(Read());
|
||||
|
||||
IEnumerator Read(){
|
||||
int subCounter = 0;
|
||||
int visibleCounter = 0;
|
||||
while(subCounter < subTexts.Length){
|
||||
if(subCounter % 2 == 1){
|
||||
yield return EvaluateTag(subTexts[subCounter].Replace(" ", ""));
|
||||
}else{
|
||||
while(visibleCounter < subTexts[subCounter].Length){
|
||||
onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
|
||||
visibleCounter++;
|
||||
maxVisibleCharacters++;
|
||||
yield return new WaitForSecondsRealtime(1f / speed);
|
||||
}
|
||||
visibleCounter = 0;
|
||||
}
|
||||
subCounter++;
|
||||
}
|
||||
yield return null;
|
||||
|
||||
WaitForSecondsRealtime EvaluateTag(string tag){
|
||||
if (tag.Length > 0){
|
||||
if (tag.StartsWith("speed=")){
|
||||
speed = float.Parse(tag.Split('=')[1]);
|
||||
}else if (tag.StartsWith("pause=")){
|
||||
return new WaitForSecondsRealtime(float.Parse(tag.Split('=')[1]));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
onDialogueFinish.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs.meta
Normal file
11
Assets/Scripts/Tools/DialogueSystem/TMP_Animated.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f713d84a3ae882945800780459e26170
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue