-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCutscene.cs
More file actions
133 lines (125 loc) · 4.79 KB
/
Cutscene.cs
File metadata and controls
133 lines (125 loc) · 4.79 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
using UnityEngine;
using System.Collections;
namespace Assets.Scripts
{
class Cutscene : MonoBehaviour
{
public TextAsset[] pages;
public Texture[] backgrounds;
public int[] whichBackgroundForWhichPage;
public float[] fontsize;
public float textSpeed;
public string tagToLookFor;
public GUIStyle style;
public GUIStyle style2;
enum State { waiting, displaying, paused };
private string[] pageStrings;
private char[] pageChars;
private System.Text.StringBuilder currentText;
private int currentPage;
private float currentLetter;
private State state;
private bool start;
void OnTriggerEnter2D(Collider2D coll)
{
if(!Data.Paused)
{
if(coll.gameObject.tag == tagToLookFor)
start=true;
else
Physics2D.IgnoreCollision(this.collider2D, coll);
}
}
void Start()
{
audio.volume = Data.SfxVol%.75f;
state = State.waiting;
currentText = new System.Text.StringBuilder();
currentPage = 0;
currentLetter = 0;
pageStrings = new string[pages.Length];
for (int i = 0; i < pages.Length;i++ )
{
pageStrings[i] = pages[i].text;
}
}
void Update()
{
if (state == State.waiting)
{
if (start)
{
Data.Paused = true;
Data.PauseEnabled = false;
state = State.displaying;
pageChars=pageStrings[currentPage].ToCharArray();
style.fontSize = (int)(Screen.width * fontsize[currentPage]);
style2.fontSize = (int)(Screen.width * fontsize[currentPage]);
}
}
else if (state == State.displaying)
{
if (CustomInput.PauseFreshPress)
{
for (int i = Mathf.RoundToInt(currentLetter); i < pageChars.Length;i++ )
currentText.Append(pageChars[i]);
state = State.paused;
}
else
{
if (currentLetter == 0)
currentText.Append(pageChars[(int)currentLetter]);
int a = (int)(currentLetter);
float temp = textSpeed;
if (CustomInput.AcceptHeld)
temp *= 2;
currentLetter += temp * Time.deltaTime;
if (a < (int)currentLetter && currentLetter < pageChars.Length)
{
currentText.Append(pageChars[(int)currentLetter]);
audio.PlayOneShot(audio.clip);
}
if (currentLetter >= pageChars.Length)
{
//currentText = new System.Text.StringBuilder(pageStrings[currentPage]);
state = State.paused;
}
}
}
else
{
if (CustomInput.AcceptFreshPress || CustomInput.PauseFreshPress)
{
currentLetter = 0;
currentPage++;
if (currentPage >= pages.Length)
{
Data.Paused = false;
Data.PauseEnabled = true;
CustomInput.voidPause();
Destroy(this.gameObject);
}
else
{
pageChars = pageStrings[currentPage].ToCharArray();
currentText = new System.Text.StringBuilder();
state = State.displaying;
style.fontSize = (int)(Screen.width * fontsize[currentPage]);
style2.fontSize = (int)(Screen.width * fontsize[currentPage]);
}
}
}
}
void OnGUI()
{
if (state != State.waiting)
{
GUI.DrawTexture(new Rect(Screen.width * .3f, Screen.height * .1f, Screen.width * .5f, Screen.height * .6f), backgrounds[whichBackgroundForWhichPage[currentPage]]);
if (whichBackgroundForWhichPage[currentPage] == 0)
GUI.Label(new Rect(Screen.width * .3f, Screen.height * .1f, Screen.width * .5f, Screen.height * .6f), currentText.ToString(), style);
else
GUI.Label(new Rect(Screen.width * .3f, Screen.height * .1f, Screen.width * .5f, Screen.height * .6f), currentText.ToString(), style2);
}
}
}
}