-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDialogueManager.cs
More file actions
150 lines (130 loc) · 4.35 KB
/
Copy pathDialogueManager.cs
File metadata and controls
150 lines (130 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class DialogueManager : MonoBehaviour
{
public TextMeshProUGUI characterName;
public TextMeshProUGUI characterSpeech;
public Image image;
public AudioSource sfxSource;
private DialogueByCharacter currentCharacter;
private Dialogue currentDialogue;
//private bool isMonologue;
private int currentBubble;
private string currentText;
private AudioClip currentSfx;
public float charInterval;
public float commaInterval;
public float periodInterval;
//public float bubbleInterval;
/*
* REPLACE THIS with appropriate GameManager attributes (i.e. should tell the GM that
the player is in a conversation that must be progressed by pressing 'E', plus when the dialogue ends
and the player's free to move again)
*/
private PlayerControl pc;
// Start is called before the first frame update
void Start()
{
pc = FindObjectOfType<PlayerControl>();
}
public void StartNewDialogue(DialogueByCharacter character, int index)
{
pc.inDialogue = true;
currentCharacter = character;
currentDialogue = currentCharacter.dialogues[index];
PlayBubble();
}
void LoadDialogue()
{
//Determines who talks first; speakers take turns
if (currentCharacter.firstSpeaker == DialogueByCharacter.SpeakingOrder.Player)
{
if (currentBubble % 2 == 0)
{
characterName.text = currentCharacter.player.characterName;
image.sprite = currentCharacter.player.image;
currentSfx = currentCharacter.player.sfx;
}
else
{
characterName.text = currentCharacter.other.characterName;
image.sprite = currentCharacter.other.image;
currentSfx = currentCharacter.other.sfx;
}
}
else
{
if (currentBubble % 2 == 0)
{
characterName.text = currentCharacter.other.characterName;
image.sprite = currentCharacter.other.image;
currentSfx = currentCharacter.other.sfx;
}
else
{
characterName.text = currentCharacter.player.characterName;
image.sprite = currentCharacter.player.image;
currentSfx = currentCharacter.player.sfx;
}
}
//Readies text/images
characterSpeech.maxVisibleCharacters = 0;
currentText = currentDialogue.bubbles[currentBubble];
characterSpeech.text = currentText;
}
//Later, should only be accessed by GM
public void PlayBubble()
{
Debug.Log(currentBubble + ", " + currentDialogue.bubbles.Length);
LoadDialogue();
if (currentBubble < currentDialogue.bubbles.Length)
{
if (currentBubble < currentDialogue.bubbles.Length - 1)
{
pc.waitingForNextBubble = true;
}
else
{
pc.waitingForNextBubble = false;
}
//At first, should bring up the dialogue boxes (hidden otherwise)
StopCoroutine(PlayChar());
StartCoroutine(PlayChar());
currentBubble++;
}
else
{
pc.inDialogue = false;
//Should hide the dialogue boxes once that convo is over
Debug.Log("Done!");
}
}
IEnumerator PlayChar()
{
WaitForSeconds wait = new WaitForSeconds(charInterval);
WaitForSeconds comWait = new WaitForSeconds(commaInterval);
WaitForSeconds perWait = new WaitForSeconds(periodInterval);
//sfxSource.clip = currentSfx;
foreach (char c in currentText.ToCharArray())
{
characterSpeech.maxVisibleCharacters++;
//sfxSource.Play();
if (c.Equals(','))
{
yield return comWait;
}
else if (c.Equals('.') || c.Equals('!') || c.Equals('?') || c.Equals('-'))
{
yield return perWait;
}
else
{
yield return wait;
}
}
//sfxSource.Stop();
}
}