movement and dialogue system
This commit is contained in:
parent
977e666577
commit
1590b5faa6
123 changed files with 62825 additions and 355 deletions
7
Assets/Scripts/Dialogue/DialogueCharacter.cs
Normal file
7
Assets/Scripts/Dialogue/DialogueCharacter.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using UnityEngine;
|
||||
[CreateAssetMenu(fileName = "New Dialogue Character", menuName = "Dialogue/Character")]
|
||||
public class DialogueCharacter : ScriptableObject
|
||||
{
|
||||
public string characterName;
|
||||
public Sprite portrait;
|
||||
}
|
||||
2
Assets/Scripts/Dialogue/DialogueCharacter.cs.meta
Normal file
2
Assets/Scripts/Dialogue/DialogueCharacter.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a4c8d6e10ec0d884abbdf0ec9d2213b
|
||||
91
Assets/Scripts/Dialogue/DialogueManager.cs
Normal file
91
Assets/Scripts/Dialogue/DialogueManager.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueManager : MonoBehaviour
|
||||
{
|
||||
#region Statication
|
||||
|
||||
public static DialogueManager instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance != null && instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Header("Dialogue Script")]
|
||||
[SerializeField] private DialogueScript currentDialogueScript;
|
||||
private int textProgress;
|
||||
public string[] scriptLines;
|
||||
[Header("UI")]
|
||||
public GameObject uiCanvas;
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI dialogueText;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartDialogue(currentDialogueScript);
|
||||
}
|
||||
|
||||
public void StartDialogue(DialogueScript scriptToShow)
|
||||
{
|
||||
uiCanvas.SetActive(true);
|
||||
currentDialogueScript = scriptToShow;
|
||||
scriptLines = currentDialogueScript.script.text.Split("\n");
|
||||
UpdateDialogue();
|
||||
}
|
||||
|
||||
private void ContinueDialogue()
|
||||
{
|
||||
textProgress++;
|
||||
UpdateDialogue();
|
||||
}
|
||||
|
||||
private void UpdateDialogue()
|
||||
{
|
||||
string[] words = scriptLines[textProgress].Split(" ");
|
||||
switch (words[0].ToUpper())
|
||||
{
|
||||
case "END":
|
||||
EndDialogue();
|
||||
break;
|
||||
case "TEXT":
|
||||
foreach (DialogueCharacter character in currentDialogueScript.characters)
|
||||
{
|
||||
if (string.Equals(character.name, words[1], StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
nameText.text = character.name;
|
||||
string text = string.Join(" ", words[2..]);
|
||||
text = text.Replace("\"", "");
|
||||
dialogueText.text = text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void EndDialogue()
|
||||
{
|
||||
//TaskManager.instance.AddTask(currentDialogueScript.taskToStart);
|
||||
uiCanvas.SetActive(false);
|
||||
currentDialogueScript = null;
|
||||
scriptLines = null;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (currentDialogueScript && Input.GetMouseButtonDown(0))
|
||||
{
|
||||
ContinueDialogue();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Dialogue/DialogueManager.cs.meta
Normal file
2
Assets/Scripts/Dialogue/DialogueManager.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e15aad8b4f467043aa1dab68b726d945
|
||||
10
Assets/Scripts/Dialogue/DialogueScript.cs
Normal file
10
Assets/Scripts/Dialogue/DialogueScript.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Dialogue Script", menuName = "Dialogue/Script")]
|
||||
public class DialogueScript : ScriptableObject
|
||||
{
|
||||
public List<DialogueCharacter> characters;
|
||||
public TextAsset script;
|
||||
public Task taskToStart;
|
||||
}
|
||||
2
Assets/Scripts/Dialogue/DialogueScript.cs.meta
Normal file
2
Assets/Scripts/Dialogue/DialogueScript.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f22a9deacfe82225495c03952e48a825
|
||||
Loading…
Add table
Add a link
Reference in a new issue