Improved logic for character sheets
added a way to retrieve sheets for characters
This commit is contained in:
48
Assets/Scripts/DialogueSystem/CharacterSheet.cs
Normal file
48
Assets/Scripts/DialogueSystem/CharacterSheet.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharacterSheet : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text m_characterNameText;
|
||||
[SerializeField] private TMP_Text m_line;
|
||||
[SerializeField] private Transform m_lineHolder;
|
||||
|
||||
private Dictionary<string, GameObject> m_lines = new Dictionary<string, GameObject>();
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
foreach (var line in m_lines)
|
||||
{
|
||||
Destroy(line.Value);
|
||||
}
|
||||
|
||||
m_lines.Clear();
|
||||
}
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
m_characterNameText.text = name;
|
||||
}
|
||||
|
||||
// Adds a line to the character sheet.
|
||||
public void AddLine(string lineText)
|
||||
{
|
||||
if (LineExists(lineText))
|
||||
return;
|
||||
|
||||
var line = Instantiate(m_line, m_lineHolder);
|
||||
line.text = lineText;
|
||||
|
||||
line.gameObject.SetActive(true);
|
||||
|
||||
m_lines.Add(lineText, line.gameObject);
|
||||
}
|
||||
|
||||
// Returns if the line has already been added.
|
||||
private bool LineExists(string lineText)
|
||||
{
|
||||
return m_lines.ContainsKey(lineText);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/DialogueSystem/CharacterSheet.cs.meta
Normal file
11
Assets/Scripts/DialogueSystem/CharacterSheet.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8b9f2f1f2da7474e964926017ec32b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,48 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharacterSheetController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text m_characterNameText;
|
||||
[SerializeField] private TMP_Text m_line;
|
||||
[SerializeField] private Transform m_lineHolder;
|
||||
public CharacterSheet m_characterSheet;
|
||||
public Transform m_characterSheetTransform;
|
||||
|
||||
private Dictionary<string, GameObject> m_lines = new Dictionary<string, GameObject>();
|
||||
private Dictionary<string, CharacterSheet> m_characterSheets = new Dictionary<string, CharacterSheet>();
|
||||
|
||||
public void Cleanup()
|
||||
// Returns if a character sheet exists for the character.
|
||||
public bool SheetExists(string characterName)
|
||||
{
|
||||
foreach(var line in m_lines)
|
||||
{
|
||||
Destroy(line.Value);
|
||||
}
|
||||
|
||||
m_lines.Clear();
|
||||
return m_characterSheets.ContainsKey(characterName);
|
||||
}
|
||||
|
||||
public void SetName(string name)
|
||||
// Get the character sheet for the passed in character.
|
||||
public CharacterSheet GetSheet(string name)
|
||||
{
|
||||
m_characterNameText.text = name;
|
||||
if (!m_characterSheets.ContainsKey(name))
|
||||
return null;
|
||||
|
||||
CharacterSheet sheet = null;
|
||||
m_characterSheets.TryGetValue(name, out sheet);
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
// Adds a line to the character sheet.
|
||||
public void AddLine(string lineText)
|
||||
// Creates a new character sheet.
|
||||
public CharacterSheet CreateSheet(string characterName)
|
||||
{
|
||||
if (LineExists(lineText))
|
||||
return;
|
||||
var sheet = Instantiate(m_characterSheet, m_characterSheetTransform);
|
||||
|
||||
var line = Instantiate(m_line, m_lineHolder);
|
||||
line.text = lineText;
|
||||
m_characterSheets.Add(characterName, sheet);
|
||||
|
||||
line.gameObject.SetActive(true);
|
||||
|
||||
m_lines.Add(lineText, line.gameObject);
|
||||
}
|
||||
|
||||
// Returns if the line has already been added.
|
||||
private bool LineExists(string lineText)
|
||||
{
|
||||
return m_lines.ContainsKey(lineText);
|
||||
return sheet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ public class QuestionData
|
||||
"Who are you?",
|
||||
"Tell me something about yourself.",
|
||||
"What is your greatest accomplishment?",
|
||||
"Where do you see yourself in five years?",
|
||||
"What are your salary requirements?"
|
||||
"Where do you see yourself in five years?"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -17,12 +19,16 @@ public class DialoguePanel : MonoBehaviour
|
||||
|
||||
private const float TypingSpeed = 0.03f;
|
||||
|
||||
private List<int> m_questionIndexAsked = new List<int>();
|
||||
private CharacterData m_currentCharacter;
|
||||
private bool m_skipped = false;
|
||||
|
||||
private int m_questionCount = QuestionData.Questions.Length;
|
||||
private int m_questionsAsked = 0;
|
||||
|
||||
private CharacterSheet m_characterSheet;
|
||||
private string m_lineToAdd = "";
|
||||
|
||||
private bool QuestionsFinished => m_questionsAsked >= m_questionCount;
|
||||
|
||||
private void Awake()
|
||||
@@ -36,18 +42,33 @@ public class DialoguePanel : MonoBehaviour
|
||||
{
|
||||
Cleanup();
|
||||
|
||||
m_characterSheetController.Cleanup();
|
||||
m_characterSheetController.SetName(characterData.name);
|
||||
|
||||
m_questionsAsked = 0;
|
||||
m_currentCharacter = characterData;
|
||||
m_characterNameText.text = characterData.name;
|
||||
|
||||
// TODO: will this be changed with an introductory text?
|
||||
m_characterText.text = "Select an option...";
|
||||
|
||||
SetupCharacterSheet();
|
||||
m_characterSheet.SetName(characterData.name);
|
||||
m_characterSheet.gameObject.SetActive(true);
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void SetupCharacterSheet()
|
||||
{
|
||||
var sheetExists = m_characterSheetController.SheetExists(m_currentCharacter.name);
|
||||
|
||||
if (sheetExists)
|
||||
{
|
||||
m_characterSheet = m_characterSheetController.GetSheet(m_currentCharacter.name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new character sheet
|
||||
m_characterSheet = m_characterSheetController.CreateSheet(m_currentCharacter.name);
|
||||
}
|
||||
|
||||
// Handles cleaing up for the next text.
|
||||
private void Cleanup()
|
||||
{
|
||||
@@ -96,6 +117,9 @@ public class DialoguePanel : MonoBehaviour
|
||||
m_skipped = true;
|
||||
m_characterText.text = text;
|
||||
|
||||
// Add the current line to the character sheet.
|
||||
PopulateCharacterSheet();
|
||||
|
||||
// If we've asked all the questions we should mark this character as interviewed and continue.
|
||||
if (QuestionsFinished)
|
||||
{
|
||||
@@ -115,11 +139,27 @@ public class DialoguePanel : MonoBehaviour
|
||||
var dialogueOption = m_currentCharacter.m_dialogueOptions[index];
|
||||
StartCoroutine(DisplayText(dialogueOption.text));
|
||||
|
||||
// TODO: we should update the sheet with this information.
|
||||
m_characterSheetController.AddLine(dialogueOption.text);
|
||||
// Setup the line to add to the character sheet once the dialogue has finished.
|
||||
m_lineToAdd = $"<b>Q.) {QuestionData.Questions[index]}\n</b>A.) {dialogueOption.bulletizedText}";
|
||||
|
||||
MarkQuestionAsked(index);
|
||||
}
|
||||
|
||||
// Marks the question as asked if it hasn't been asked already.
|
||||
private void MarkQuestionAsked(int index)
|
||||
{
|
||||
if (m_questionIndexAsked.Contains(index))
|
||||
return;
|
||||
|
||||
// Increment questions asked.
|
||||
m_questionsAsked++;
|
||||
m_questionIndexAsked.Add(index);
|
||||
}
|
||||
|
||||
private void PopulateCharacterSheet()
|
||||
{
|
||||
m_characterSheet.AddLine(m_lineToAdd);
|
||||
m_lineToAdd = "";
|
||||
}
|
||||
|
||||
// Callback from Unity on the skip button.
|
||||
|
||||
Reference in New Issue
Block a user