2023-04-25 13:27:12 -07:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using TMPro;
|
2023-05-02 16:41:07 -07:00
|
|
|
using UnityEngine.UI;
|
2023-04-25 13:27:12 -07:00
|
|
|
|
|
|
|
public class DialogBoxes : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
[Header("Dialog Messages:")]
|
|
|
|
[SerializeField] string[] dialogMessages;
|
|
|
|
private TMP_Text textField;
|
|
|
|
private int messageCount = 0;
|
|
|
|
|
2023-05-02 16:41:07 -07:00
|
|
|
[Header("Images:")]
|
|
|
|
[SerializeField] Image backgroundImageObject;
|
|
|
|
[SerializeField] Sprite[] images;
|
|
|
|
|
|
|
|
|
2023-04-25 13:27:12 -07:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
textField = this.gameObject.GetComponent<TMP_Text>();
|
2023-05-02 16:41:07 -07:00
|
|
|
ReconfigureSpriteArray();
|
2023-04-25 13:27:12 -07:00
|
|
|
textField.text = dialogMessages[0];
|
2023-05-02 16:41:07 -07:00
|
|
|
backgroundImageObject.sprite = images[0];
|
2023-04-25 13:27:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnAdvanceDialog() {
|
|
|
|
messageCount += 1;
|
|
|
|
if (messageCount < dialogMessages.Length) {
|
|
|
|
textField.text = dialogMessages[messageCount];
|
2023-05-02 16:41:07 -07:00
|
|
|
backgroundImageObject.sprite = images[messageCount];
|
2023-04-25 13:27:12 -07:00
|
|
|
} else { // no more dialog messages, advance the scene
|
|
|
|
GameObject.Find("SceneManager").GetComponent<SceneController>().NextScene();
|
|
|
|
}
|
|
|
|
}
|
2023-05-02 16:41:07 -07:00
|
|
|
|
|
|
|
void ReconfigureSpriteArray() {
|
|
|
|
// resize if need to
|
|
|
|
if (images.Length != dialogMessages.Length) {
|
|
|
|
Sprite[] newImagesArray = new Sprite[dialogMessages.Length];
|
|
|
|
for (int i = 0; i < newImagesArray.Length; i++) {
|
|
|
|
newImagesArray[i] = images[i];
|
|
|
|
}
|
|
|
|
images = newImagesArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update empty slots
|
|
|
|
for (int i = 1; i < images.Length; i++) {
|
|
|
|
if (images[i] == null ) {
|
|
|
|
images[i] = images[i-1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-04-25 13:27:12 -07:00
|
|
|
}
|