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
|
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Expands a list of 4-byte parameters into a longer list of (effectively)
// 1-byte parameters. The 1-byte parameters are easier to use in an animation
// layer, since we can write conditions for them.
[SharedBetweenAnimators]
public class SetLetters : StateMachineBehaviour
{
Dictionary<string, int> letters_;
List<string> cell_parameters_;
List<string> group_parameters_;
int GetLetterFromGroup(int g, int which)
{
return (((g & (0x000000FF << (which * 8))) >> (which * 8)) & 0x000000FF);
}
// This function is called in 2 contexts:
// 1. animator.parameters contains everything we need. Updating params is not
// reflected in emulator.
// 2. animator.parameters contains nothing we need. Updating params is
// reflected in emulator.
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (letters_ == null) {
letters_ = new Dictionary<string, int>();
}
// I don't know why or how but Unity fucking refuses to save this variable,
// so reinitialize it every time, YOLO.
cell_parameters_ = new List<string> {
"_Letter_Row00_Col00",
"_Letter_Row00_Col01",
"_Letter_Row00_Col02",
"_Letter_Row00_Col03",
"_Letter_Row00_Col04",
"_Letter_Row00_Col05",
"_Letter_Row00_Col06",
"_Letter_Row00_Col07",
"_Letter_Row00_Col08",
"_Letter_Row00_Col09",
"_Letter_Row00_Col10",
"_Letter_Row00_Col11",
"_Letter_Row00_Col12",
"_Letter_Row00_Col13",
"_Letter_Row01_Col00",
"_Letter_Row01_Col01",
"_Letter_Row01_Col02",
"_Letter_Row01_Col03",
"_Letter_Row01_Col04",
"_Letter_Row01_Col05",
"_Letter_Row01_Col06",
"_Letter_Row01_Col07",
"_Letter_Row01_Col08",
"_Letter_Row01_Col09",
"_Letter_Row01_Col10",
"_Letter_Row01_Col11",
"_Letter_Row01_Col12",
"_Letter_Row01_Col13",
"_Letter_Row02_Col00",
"_Letter_Row02_Col01",
"_Letter_Row02_Col02",
"_Letter_Row02_Col03",
"_Letter_Row02_Col04",
"_Letter_Row02_Col05",
"_Letter_Row02_Col06",
"_Letter_Row02_Col07",
"_Letter_Row02_Col08",
"_Letter_Row02_Col09",
"_Letter_Row02_Col10",
"_Letter_Row02_Col11",
"_Letter_Row02_Col12",
"_Letter_Row02_Col13",
"_Letter_Row03_Col00",
"_Letter_Row03_Col01",
"_Letter_Row03_Col02",
"_Letter_Row03_Col03",
"_Letter_Row03_Col04",
"_Letter_Row03_Col05",
"_Letter_Row03_Col06",
"_Letter_Row03_Col07",
"_Letter_Row03_Col08",
"_Letter_Row03_Col09",
"_Letter_Row03_Col10",
"_Letter_Row03_Col11",
"_Letter_Row03_Col12",
"_Letter_Row03_Col13",
"_Letter_Row04_Col00",
"_Letter_Row04_Col01",
"_Letter_Row04_Col02",
"_Letter_Row04_Col03",
"_Letter_Row04_Col04",
"_Letter_Row04_Col05",
"_Letter_Row04_Col06",
"_Letter_Row04_Col07",
"_Letter_Row04_Col08",
"_Letter_Row04_Col09",
"_Letter_Row04_Col10",
"_Letter_Row04_Col11",
"_Letter_Row04_Col12",
"_Letter_Row04_Col13",
"_Letter_Row05_Col00",
"_Letter_Row05_Col01",
"_Letter_Row05_Col02",
"_Letter_Row05_Col03",
"_Letter_Row05_Col04",
"_Letter_Row05_Col05",
"_Letter_Row05_Col06",
"_Letter_Row05_Col07",
"_Letter_Row05_Col08",
"_Letter_Row05_Col09",
"_Letter_Row05_Col10",
"_Letter_Row05_Col11",
"_Letter_Row05_Col12",
"_Letter_Row05_Col13",
};
group_parameters_ = new List<string> {
"_Letter_Row00_Col00_03",
"_Letter_Row00_Col04_07",
"_Letter_Row00_Col08_11",
"_Letter_Row00_Col12_13",
"_Letter_Row01_Col00_03",
"_Letter_Row01_Col04_07",
"_Letter_Row01_Col08_11",
"_Letter_Row01_Col12_13",
"_Letter_Row02_Col00_03",
"_Letter_Row02_Col04_07",
"_Letter_Row02_Col08_11",
"_Letter_Row02_Col12_13",
"_Letter_Row03_Col00_03",
"_Letter_Row03_Col04_07",
"_Letter_Row03_Col08_11",
"_Letter_Row03_Col12_13",
"_Letter_Row04_Col00_03",
"_Letter_Row04_Col04_07",
"_Letter_Row04_Col08_11",
"_Letter_Row04_Col12_13",
"_Letter_Row05_Col00_03",
"_Letter_Row05_Col04_07",
"_Letter_Row05_Col08_11",
"_Letter_Row05_Col12_13",
};
bool got_match = false;
foreach (var param in animator.parameters) {
if (param.name == "_Letter_Row00_Col00_03") {
got_match = true;
break;
}
}
if (!got_match) {
if (!letters_.ContainsKey(cell_parameters_[0])) {
return;
}
foreach (var param in cell_parameters_) {
animator.SetInteger(param, letters_[param]);
}
return;
}
int cell_idx = 0;
for (int i = 0; i < group_parameters_.Count; i++) {
string group_param = group_parameters_[i];
int g = animator.GetInteger(group_param);
string cell_param = cell_parameters_[cell_idx];
letters_[cell_param] = GetLetterFromGroup(g, 0);
cell_idx += 1;
cell_param = cell_parameters_[cell_idx];
letters_[cell_param] = GetLetterFromGroup(g, 1);
cell_idx += 1;
// If we're on the last group of 4 in a row, we do not look at the cells,
// since there are only 14 cells in each row.
if (i % 4 != 3) {
cell_param = cell_parameters_[cell_idx];
letters_[cell_param] = GetLetterFromGroup(g, 2);
cell_idx += 1;
cell_param = cell_parameters_[cell_idx];
letters_[cell_param] = GetLetterFromGroup(g, 3);
cell_idx += 1;
}
}
}
}
|