You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.2 KiB
122 lines
3.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
public static UIManager instance;
|
|
public bool openingStatus;
|
|
public GameObject dialogueBox;
|
|
public Text characterNameText;
|
|
public Text dialogueLineText;
|
|
public GameObject spaceBar;
|
|
float scrollingSpeed = 0.02f;
|
|
bool isScrolling;
|
|
[TextArea(1,3)] public string[] dialogueLines;
|
|
[SerializeField] int currentLine;
|
|
|
|
private void Awake()
|
|
{
|
|
if(instance == null)
|
|
instance = this;
|
|
else if(instance != this)
|
|
Destroy(this);
|
|
//DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
dialogueLineText.text = dialogueLines[currentLine];
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(dialogueBox.activeInHierarchy && GameManager.instance.gameMode == GameManager.GameMode.Normal)
|
|
{
|
|
if(Input.GetKeyUp("x"))
|
|
{
|
|
if(!isScrolling)
|
|
{
|
|
currentLine ++;
|
|
if(currentLine < dialogueLines.Length)
|
|
{
|
|
CheckName();
|
|
StartCoroutine(ScrollingText());
|
|
}
|
|
else
|
|
{
|
|
characterNameText.gameObject.SetActive(true);
|
|
dialogueBox.SetActive(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
scrollingSpeed = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ToggleDialogueBox(bool value)
|
|
{
|
|
dialogueBox.SetActive(value);
|
|
}
|
|
|
|
public void ToggleSpaceBar(bool value)
|
|
{
|
|
spaceBar.SetActive(value);
|
|
}
|
|
|
|
public void SetupDialogue(string name, string dialogue, int size)
|
|
{
|
|
characterNameText.text = name;
|
|
dialogueLineText.fontSize = size;
|
|
StartCoroutine(ScrollingCGText(dialogue));
|
|
ToggleDialogueBox(true);
|
|
}
|
|
|
|
public void ShowDialogue(string[] currentDialogueLines, bool hasName = true)
|
|
{
|
|
characterNameText.gameObject.SetActive(hasName);
|
|
currentLine = 0;
|
|
dialogueLines = currentDialogueLines;
|
|
CheckName();
|
|
dialogueBox.SetActive(true);
|
|
StartCoroutine(ScrollingText());
|
|
}
|
|
void CheckName()
|
|
{
|
|
if(dialogueLines[currentLine].StartsWith("n-"))
|
|
{
|
|
characterNameText.text = dialogueLines[currentLine].Replace("n-","");
|
|
currentLine++;
|
|
}
|
|
}
|
|
|
|
IEnumerator ScrollingText()
|
|
{
|
|
isScrolling = true;
|
|
dialogueLineText.text = "";
|
|
char[] text = dialogueLines[currentLine].ToCharArray();
|
|
foreach(char letter in text)
|
|
{
|
|
dialogueLineText.text += letter;
|
|
yield return new WaitForSeconds(scrollingSpeed);
|
|
}
|
|
isScrolling = false;
|
|
scrollingSpeed = 0.02f;
|
|
}
|
|
|
|
IEnumerator ScrollingCGText(string dialogue)
|
|
{
|
|
dialogueLineText.text = "";
|
|
char[] text = dialogue.ToCharArray();
|
|
foreach(char letter in text)
|
|
{
|
|
dialogueLineText.text += letter;
|
|
yield return new WaitForSeconds(scrollingSpeed);
|
|
}
|
|
}
|
|
}
|