/
SceneFive.cs
134 lines (108 loc) · 3.08 KB
/
SceneFive.cs
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
using UnityEngine;
using System;
class SceneFive : Scene {
GameObject background;
GameObject faceLeft;
GameObject faceRight;
BigMouthAnimator bigMouthAnimator;
LipsAppear lips;
public SceneFive(SceneManager manager) : base(manager) {
}
public override void Setup () {
timeLength = 4.0f;
//endScene(); // no interaction required to continue
background = resourceFactory.Create(this, "PurpleQuad");
faceLeft = resourceFactory.Create(this, "FaceLeft");
var leftPosition = faceLeft.transform.position;
leftPosition.x = -5f;
leftPosition.y = -6f;
faceLeft.transform.position = leftPosition;
faceRight = resourceFactory.Create(this, "FaceRight");
var rightPosition = faceRight.transform.position;
rightPosition.x = 1f;
rightPosition.y = -6f;
faceRight.transform.position = rightPosition;
bigMouthAnimator = new BigMouthAnimator(resourceFactory);
lips = new LipsAppear(resourceFactory);
}
public override void Update () {
bigMouthAnimator.Update(Time.time);
lips.Update(Time.time);
}
public override void Destroy () {
GameObject.Destroy(background);
GameObject.Destroy(faceLeft);
GameObject.Destroy(faceRight);
bigMouthAnimator.Destroy();
lips.Destroy();
}
class LipsAppear : Repeater {
GameObject lips;
public LipsAppear(GameObjectFactory<string> resourceFactory) : base(0.5f) {
lips = resourceFactory.Create("SceneFive/Lips");
var lipsPosition = lips.transform.position;
lipsPosition.x = -6f;
lipsPosition.y = -5f;
lipsPosition.z = -1f;
lips.transform.position = lipsPosition;
lips.active = false;
}
public override void OnTick ()
{
if(currentTick > 6) {
lips.active = true;
}
if(currentTick == 8) {
Reset(Time.time);
lips.active = false;
}
}
public void Destroy() {
GameObject.Destroy(lips);
}
}
class BigMouthAnimator : Repeater {
GameObject mouthLeft;
GameObject mouthRight;
int delay = 1;
int frame = 0;
const int totalFrames = 8;
public BigMouthAnimator(GameObjectFactory<string> resourceFactory) : base(0.25f) {
mouthLeft = resourceFactory.Create("SceneFive/MouthLeft");
var leftPosition = mouthLeft.transform.position;
leftPosition.x = -2.95f;
leftPosition.y = -5.6f;
leftPosition.z = -0.5f;
mouthLeft.transform.position = leftPosition;
mouthRight = resourceFactory.Create("SceneFive/MouthRight");
var rightPosition = mouthRight.transform.position;
rightPosition.x = 1f;
rightPosition.y = -5.6f;
rightPosition.z = -0.5f;
mouthRight.transform.position = rightPosition;
}
public override void OnTick() {
if (delay > 0) {
delay -= 1;
return;
}
moveMouth(0, 4);
moveMouth(5, 10);
moveMouth(10, 11);
incrementFrame();
}
public void Destroy() {
GameObject.Destroy(mouthLeft);
GameObject.Destroy(mouthRight);
}
private void incrementFrame() {
frame = (frame + 1) % totalFrames;
}
private void moveMouth(int start, int end) {
if(frame > start && frame < end) {
mouthLeft.GetComponent<Sprite>().NextTexture();
mouthRight.GetComponent<Sprite>().NextTexture();
}
}
}
}