-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickableObject.cs
More file actions
157 lines (122 loc) · 5 KB
/
ClickableObject.cs
File metadata and controls
157 lines (122 loc) · 5 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickableObject : MonoBehaviour, IPointerClickHandler
{
Calculation calculation; // this variable accesses the main instance of calculation, allowing this script to access the variables and functions in that script
public enum ButtonType { zero, one, two, three, four, five, six, seven, eight, nine, add, subtract, multiply, divide, cos1, sin1, tan1, log, ln, cos, sin, tan, sq, sqrt, ans, range, negative, lbrackets, rbrackets, dot, equals, delete, clear };
public ButtonType buttonType; // an enum is created to hold all of the different things a button can do, and then this variable to hold that enum type. This variable is assigned in the editor
void Start()
{
calculation = Calculation.instance; // assign the var to the main instance
}
public void OnPointerClick(PointerEventData eventData)
{ // the OnPointerClick event runs when the GameObject this script is attached to is clicked
if (PointerEventData.InputButton.Left == eventData.button)
{ // if it was LEFT clicked, than we run a function in our main script depending on the individual enum assigned
switch (buttonType)
{
case ButtonType.add:
calculation.AddOperator(2);
break;
case ButtonType.ans:
calculation.AddMostRecentAns();
break;
case ButtonType.clear:
calculation.ClearEquation();
break;
case ButtonType.cos:
calculation.AddFunction(5);
break;
case ButtonType.cos1:
calculation.AddFunction(0);
break;
case ButtonType.delete:
calculation.DeleteMostRecent();
break;
case ButtonType.divide:
calculation.AddOperator(1);
break;
case ButtonType.dot:
calculation.AddDecimal();
break;
case ButtonType.eight:
calculation.AddNumber(8);
break;
case ButtonType.equals:
calculation.EqualsPressed();
break;
case ButtonType.five:
calculation.AddNumber(5);
break;
case ButtonType.four:
calculation.AddNumber(4);
break;
case ButtonType.lbrackets:
calculation.AddBrackets();
break;
case ButtonType.ln:
calculation.AddFunction(4);
break;
case ButtonType.log:
calculation.AddFunction(3);
break;
case ButtonType.multiply:
calculation.AddOperator(0);
break;
case ButtonType.negative:
calculation.AddNegative();
break;
case ButtonType.nine:
calculation.AddNumber(9);
break;
case ButtonType.one:
calculation.AddNumber(1);
break;
case ButtonType.range:
calculation.EnterRandomRangeRange();
break;
case ButtonType.rbrackets:
calculation.ExitBrackets();
break;
case ButtonType.seven:
calculation.AddNumber(7);
break;
case ButtonType.sin:
calculation.AddFunction(6);
break;
case ButtonType.sin1:
calculation.AddFunction(1);
break;
case ButtonType.six:
calculation.AddNumber(6);
break;
case ButtonType.sq:
calculation.AddFunction(8);
break;
case ButtonType.sqrt:
calculation.AddFunction(9);
break;
case ButtonType.subtract:
calculation.AddOperator(3);
break;
case ButtonType.tan:
calculation.AddFunction(7);
break;
case ButtonType.tan1:
calculation.AddFunction(2);
break;
case ButtonType.three:
calculation.AddNumber(3);
break;
case ButtonType.two:
calculation.AddNumber(2);
break;
case ButtonType.zero:
calculation.AddNumber(0);
break;
}
}
}
}