/
MemeGenerator.cs
105 lines (85 loc) · 2.1 KB
/
MemeGenerator.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
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using System;
using UnityEngine.UI;
public class MemeGenerator : MonoBehaviour {
Meme levelMeme;
CanvasController canvasController;
public Timer timer;
bool gameIsOn = true;
public bool memePosted = false;
Sprite levelPicture;
string topLine;
string bottomLine;
public Action<Meme> cbMemeCreated;
public Action<String> cbTopLineChanged;
public Action<String> cbBottomLineChanged;
void Awake () {
timer = new Timer(Time.time, 9, 6);
}
// Use this for initialization
void Start () {
cbMemeCreated += ShowDebug;
timer.cbTimesUp += OnTimeUp;
canvasController = FindObjectOfType<CanvasController>();
}
// Update is called once per frame
void Update () {
timer.UpdateTime(Time.time);
}
public void CreateMeme (Button button) {
Meme meme = new Meme (topLine, bottomLine, levelPicture);
if (cbMemeCreated != null) {
cbMemeCreated(meme);
}
memePosted = !memePosted;
ChangeButtonColor(button);
}
void ShowDebug (Meme meme) {
Debug.Log(meme.topLine + "\n" + bottomLine);
}
public void ChangeTopLine (string txt) {
Debug.Log("ChangeTopLine ---- " + txt);
if (txt == null) {
return;
}
topLine = txt;
if (cbTopLineChanged != null) {
cbTopLineChanged(txt);
}
}
public void ChangeBottomLine (string txt) {
Debug.Log("ChangeBottomLine ---- " + txt);
if (txt == null) {
return;
}
bottomLine = txt;
if (cbBottomLineChanged != null) {
cbBottomLineChanged(txt);
}
}
void OnTimeUp () {
Debug.Log("Moving Scene");
SceneManager.LoadScene("Voting");
}
public void ChangeButtonColor (Button button) {
Debug.Log("Changing the button color!");
Color newColor;
String buttonText;
if (memePosted) {
newColor = Color.red;
buttonText = "Undo";
canvasController.ift.SetActive(false);
canvasController.ifb.SetActive(false);
}
else {
newColor = Color.blue;
buttonText = "Post";
canvasController.ift.SetActive(true);
canvasController.ifb.SetActive(true);
}
button.image.color = newColor;
button.GetComponentInChildren<Text>().text = buttonText;
}
}