-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBoxManager.cs
More file actions
212 lines (153 loc) · 6.22 KB
/
TextBoxManager.cs
File metadata and controls
212 lines (153 loc) · 6.22 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class TextBoxManager : MonoBehaviour
{
public GameObject textBox;
public TextMeshProUGUI theText;
public string[] textLines;
public float[] typeSpeedArray;
public int currentLine;
public int endAtLine;
public bool on;
public bool isTyping = false;
public bool cancelTyping = false;
public float typeSpeed;
public Sprite textimg;
public GameObject clickPrompt;
public GameObject tiedInteractable;
void Awake()
{
}
// Start is called before the first frame update
void Start()
{
clickPrompt = transform.Find("ClickPromptTextBox").gameObject;
clickPrompt.SetActive(false);
/*
theText = transform.GetChild(0).GetComponent<TextMeshProUGUI>();
typeSpeed = tiedInteractable.GetComponent<Interactable>().typeSpeed;
//textLines = tiedInteractable.GetComponent<Interactable>().textLines;
endAtLine = tiedInteractable.GetComponent<Interactable>().endLine;
if(tiedInteractable.GetComponent<Interactable>().textImg != null)
{
textimg = tiedInteractable.GetComponent<Interactable>().textImg;
transform.GetChild(1).GetComponent<Image>().sprite = textimg;
}
if (tiedInteractable.GetComponent<Interactable>().typeSpeedArray.Length != 0)
{
typeSpeedArray = tiedInteractable.GetComponent<Interactable>().typeSpeedArray;
}
else
{
typeSpeedArray = new float[endAtLine+1];
for(int i = 0; i < typeSpeedArray.Length; i++)
{
typeSpeedArray[i] = typeSpeed;
}
}
*/
GetComponent<RectTransform>().anchoredPosition3D = new Vector3(0, -350, 0);
on = false;
OnOpen();
textBox = gameObject;
currentLine = 0;
//UpdateLine();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0) && on)
{
if (!isTyping)
{
currentLine++;
//UpdateLine();
if (currentLine > endAtLine)
{
on = false;
OnClose();
}
else
{
StartCoroutine(TextScoll(textLines[currentLine]));
}
}
else if(isTyping && !cancelTyping)
{
cancelTyping = true;
clickPrompt.SetActive(true);
}
}
}
private IEnumerator TextScoll(string lineOfText)
{
clickPrompt.SetActive(false);
int letter = 0;
theText.text = "";
isTyping = true;
cancelTyping = false;
while (isTyping && !cancelTyping && (letter < textLines[currentLine].Length))
{
typeSpeed = typeSpeedArray[currentLine];
theText.text = textLines[currentLine].Substring(0,letter);
letter++;
yield return new WaitForSecondsRealtime(typeSpeed);
}
theText.text = textLines[currentLine];
clickPrompt.SetActive(true);
isTyping = false;
cancelTyping = false;
}
void UpdateLine()
{
theText.text = textLines[currentLine];
}
void OnOpen()
{
LeanTween.scale(gameObject, new Vector3(6.675f, 2.175f, 6f), 0.25f).setOnComplete(SetActive).setIgnoreTimeScale(true);
LeanTween.value(gameObject, -350, -150, 0.25f).setIgnoreTimeScale(true).setOnUpdate((float val) => {
GetComponent<RectTransform>().anchoredPosition3D = new Vector3(0, val, 0);
});
GameObject.Find("Player").GetComponent<PlayerController>().midTele = true;
GameObject.Find("LevelController").GetComponent<PauseMenu>().canMenu = false;
GetComponent<SoundSampleAdd>().PlaySound(0, 1);
GameObject.Find("LevelController").GetComponent<PauseMenu>().HideUI(true);
GameObject.Find("Crosshair").GetComponent<SpriteRenderer>().enabled = false;
GameObject.Find("RootShoot").GetComponent<Shoot>().shootEnable = false;
GameObject.Find("Player").GetComponent<PlayerController>().interactEnable = false;
GameObject.Find("LevelController").GetComponent<PauseMenu>().inInventory = true;
Time.timeScale = 0;
//tiedInteractable.GetComponent<Interactable>().canInteract = false;
}
public void OnClose()
{
GameObject.Find("LevelController").GetComponent<PauseMenu>().canMenu = true;
GameObject.Find("LevelController").GetComponent<PauseMenu>().HideUI(false);
LeanTween.scale(gameObject, new Vector3(6.675f, 0f, 0f), 0.25f).setOnComplete(DestroyMe).setIgnoreTimeScale(true);
LeanTween.value(gameObject, -150, -350, 0.25f).setIgnoreTimeScale(true).setOnUpdate((float val) => {
GetComponent<RectTransform>().anchoredPosition3D = new Vector3(0, val, 0);
});
GameObject.Find("Crosshair").GetComponent<SpriteRenderer>().enabled = true;
GameObject.Find("RootShoot").GetComponent<Shoot>().shootEnable = true;
GameObject.Find("Player").GetComponent<PlayerController>().interactEnable = true;
GameObject.Find("LevelController").GetComponent<PauseMenu>().inInventory = false;
Time.timeScale = 1;
GameObject.Find("Player").GetComponent<PlayerController>().midTele = false;
GameObject.Find("RootShoot").GetComponent<Shoot>().shootEnable = true;
// tiedInteractable.GetComponent<Interactable>().clicked = true;
//tiedInteractable.GetComponent<Interactable>().canInteract = true;
}
void DestroyMe()
{
//tiedInteractable.GetComponent<Interactable>().canInteract = true;
Destroy(gameObject);
}
void SetActive()
{
StartCoroutine(TextScoll(textLines[currentLine]));
on = true;
}
}