120 lines
3.5 KiB
C#
120 lines
3.5 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
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("Status")]
|
|
public DialogueScript scriptToShow;
|
|
public int currentText;
|
|
public bool dialogueActive;
|
|
[Header("UI")]
|
|
[SerializeField] private GameObject dialogueUI;
|
|
[SerializeField] private Transform bossSpeechBubble;
|
|
[SerializeField] private Vector3 offset;
|
|
[SerializeField] private TextMeshProUGUI bossText;
|
|
[SerializeField] private GameObject youmuSpeechBubble;
|
|
[SerializeField] private TextMeshProUGUI youmuText;
|
|
[SerializeField] private GameObject reisenSpeechBubble; //have to change the dialogue for this but it's probably fine
|
|
[SerializeField] private TextMeshProUGUI reisenText;
|
|
[Header("Animation")]
|
|
[SerializeField] private Animator reisenAnimator;
|
|
[SerializeField] private Animator youmuAnimator;
|
|
[SerializeField] private string switchToDialogueTrigger;
|
|
[SerializeField] private string switchToIdleTrigger;
|
|
[SerializeField] private string changeDialogueTrigger;
|
|
[SerializeField] private string talkTrigger;
|
|
|
|
|
|
public void StartDialogue(DialogueScript newDialogue)
|
|
{
|
|
dialogueUI.SetActive(true);
|
|
dialogueActive = true;
|
|
currentText = 0;
|
|
scriptToShow = newDialogue;
|
|
DialogueScript.Dialogue currentDialogue = scriptToShow.dialogueList[currentText];
|
|
bossSpeechBubble.transform.position = WaveManager.instance.bossInstance.transform.position + offset;
|
|
SetDialogue(currentDialogue);
|
|
reisenAnimator.SetTrigger(switchToDialogueTrigger);
|
|
youmuAnimator.SetTrigger(switchToDialogueTrigger);
|
|
//GameManager.instance.SetPause(true);
|
|
}
|
|
|
|
public void ContinueDialogue()
|
|
{
|
|
currentText++;
|
|
if (currentText >= scriptToShow.dialogueList.Length)
|
|
{
|
|
EndDialogue();
|
|
return;
|
|
}
|
|
DialogueScript.Dialogue currentDialogue = scriptToShow.dialogueList[currentText];
|
|
SetDialogue(currentDialogue);
|
|
}
|
|
|
|
public void EndDialogue()
|
|
{
|
|
dialogueActive = false;
|
|
dialogueUI.SetActive(false);
|
|
WaveManager.instance.player.isStalled = false;
|
|
WaveManager.instance.bossInstance.isStalled = false;
|
|
//GameManager.instance.SetPause(false);
|
|
reisenAnimator.SetTrigger(switchToIdleTrigger);
|
|
youmuAnimator.SetTrigger(switchToIdleTrigger);
|
|
}
|
|
|
|
private void SetDialogue(DialogueScript.Dialogue textToShow)
|
|
{
|
|
reisenSpeechBubble.SetActive(false);
|
|
youmuSpeechBubble.SetActive(false);
|
|
bossSpeechBubble.gameObject.SetActive(false);
|
|
switch (textToShow.character.thisCharacter) //everyone will hate this code but that's alright
|
|
{
|
|
case DialogueCharacter.Character.Reisen:
|
|
reisenSpeechBubble.SetActive(true);
|
|
reisenText.text = textToShow.text;
|
|
youmuAnimator.SetTrigger(changeDialogueTrigger);
|
|
reisenAnimator.SetTrigger(talkTrigger);
|
|
break;
|
|
case DialogueCharacter.Character.Youmu:
|
|
youmuSpeechBubble.SetActive(true);
|
|
youmuText.text = textToShow.text;
|
|
youmuAnimator.SetTrigger(talkTrigger);
|
|
reisenAnimator.SetTrigger(changeDialogueTrigger);
|
|
break;
|
|
case DialogueCharacter.Character.Enemy:
|
|
bossSpeechBubble.gameObject.SetActive(true);
|
|
bossText.text = textToShow.text;
|
|
reisenAnimator.SetTrigger(changeDialogueTrigger);
|
|
youmuAnimator.SetTrigger(changeDialogueTrigger);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (dialogueActive)
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
ContinueDialogue();
|
|
}
|
|
}
|
|
}
|
|
}
|