Files
gmtk-2023/Assets/Scripts/DialogueSystem/CharacterSheet.cs
Amaan Shawkath c4b5d7dac3 Improved logic for character sheets
added a way to retrieve sheets for characters
2023-07-08 18:06:06 +01:00

49 lines
1.1 KiB
C#

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);
}
}