initial setup of dialogue panel and updating some scripts
This commit is contained in:
@@ -5,12 +5,12 @@ using UnityEngine;
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class Dialogue
|
public class Dialogue
|
||||||
{
|
{
|
||||||
[SerializeField] private string m_dialogueText;
|
public string text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QuestionData
|
public class QuestionData
|
||||||
{
|
{
|
||||||
public string[] m_questions = new string[]
|
public static string[] Questions = new string[]
|
||||||
{
|
{
|
||||||
"Who are you?",
|
"Who are you?",
|
||||||
"Tell me something about yourself.",
|
"Tell me something about yourself.",
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class DialogueController : MonoBehaviour
|
public class DialogueController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[SerializeField] private DialoguePanel m_dialoguePanel;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - Load the correct character based on the character who has been interacted with
|
// - Load the correct character based on the character who has been interacted with
|
||||||
// - Display the 5 question options and hook up their responses
|
// - Display the 5 question options and hook up their responses
|
||||||
|
|||||||
8
Assets/Scripts/DialogueSystem/UI.meta
Normal file
8
Assets/Scripts/DialogueSystem/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0bd66c3ec3a21b440be0d261ae3eaf95
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
95
Assets/Scripts/DialogueSystem/UI/DialoguePanel.cs
Normal file
95
Assets/Scripts/DialogueSystem/UI/DialoguePanel.cs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class DialoguePanel : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private Transform m_questionHolder;
|
||||||
|
[SerializeField] private Button m_questionButton;
|
||||||
|
|
||||||
|
[SerializeField] private TMP_Text m_characterNameText;
|
||||||
|
[SerializeField] private TMP_Text m_characterText;
|
||||||
|
|
||||||
|
private const float TypingSpeed = 0.02f;
|
||||||
|
|
||||||
|
private CharacterData m_currentCharacter;
|
||||||
|
private bool m_skipped = false;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
PopulateQuestionButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setup(CharacterData characterData)
|
||||||
|
{
|
||||||
|
Cleanup();
|
||||||
|
|
||||||
|
m_currentCharacter = characterData;
|
||||||
|
m_characterNameText.text = characterData.name;
|
||||||
|
|
||||||
|
// TODO: will this be changed with an introductory text?
|
||||||
|
m_characterText.text = "Select an option...";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cleanup()
|
||||||
|
{
|
||||||
|
m_skipped = false;
|
||||||
|
m_characterText.text = "";
|
||||||
|
|
||||||
|
StopAllCoroutines();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populates the questions the player can ask the NPC.
|
||||||
|
private void PopulateQuestionButtons()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < QuestionData.Questions.Length; i++)
|
||||||
|
{
|
||||||
|
var buttonObj = Instantiate(m_questionButton, m_questionHolder);
|
||||||
|
|
||||||
|
// Sets the button text to the question text.
|
||||||
|
var buttonText = buttonObj.GetComponentInChildren<TMP_Text>();
|
||||||
|
buttonText.text = QuestionData.Questions[i];
|
||||||
|
|
||||||
|
var button = buttonObj.GetComponent<Button>();
|
||||||
|
button.onClick.AddListener(() => OnQuestionButtonClicked(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator DisplayText(string text)
|
||||||
|
{
|
||||||
|
// Hide the questions whilst the character is talking.
|
||||||
|
m_questionHolder.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
foreach (char letter in text.ToCharArray())
|
||||||
|
{
|
||||||
|
if (m_skipped)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_characterText.text += letter;
|
||||||
|
yield return new WaitForSeconds(TypingSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_skipped = true;
|
||||||
|
m_characterText.text = text;
|
||||||
|
|
||||||
|
// Re-enable the questions.
|
||||||
|
m_questionHolder.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handles displaying the correct dialogue for the question.
|
||||||
|
private void OnQuestionButtonClicked(int index)
|
||||||
|
{
|
||||||
|
Debug.Log("Player picked option " + index);
|
||||||
|
|
||||||
|
Cleanup();
|
||||||
|
|
||||||
|
var dialogueOption = m_currentCharacter.m_dialogueOptions[index];
|
||||||
|
StartCoroutine(DisplayText(dialogueOption.text));
|
||||||
|
|
||||||
|
// TODO: we should update the sheet with this information.
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/DialogueSystem/UI/DialoguePanel.cs.meta
Normal file
11
Assets/Scripts/DialogueSystem/UI/DialoguePanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 91eb3fe780abca14d9a12fb493b16fd6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user