-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomizev2.cs
More file actions
206 lines (167 loc) · 6.26 KB
/
Copy pathRandomizev2.cs
File metadata and controls
206 lines (167 loc) · 6.26 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using System.IO;
using UnityStandardAssets.Characters.FirstPerson;
public class Randomizev2 : MonoBehaviour
{
// Creating a HashSet of odd numbers
HashSet<int> levels = new HashSet<int>();
private int numlevel = 25;
private static bool created = false;
public static int nextLevel = 0;
string FILE_NAME = "position.txt";
string OBJ_FILE_NAME = "objdistance.txt";
public static Vector3 playerStart;
public static int currentLevel;
public static float startTime;
public bool learnTrialsCompleted = false;
public bool practiceTrialsCompleted = false;
public int learnTrials = 1;
public int practiceTrials = 1;
public static bool OFT_COMPLETE = false;
private bool instructions = false;
private bool practiceInstructionsViewed = false;
private bool testInstructionsViewed = false;
void Start()
{
}
void LevelPick(){
// Check to see if Learning trials have been completed, if not,
// select the next learning trial in sequential order.
if (learnTrialsCompleted && practiceTrialsCompleted && testInstructionsViewed)
{
ParticipantLog.trialPhase = 3;
// While levels completed do not reach max trials, randomly select without replacement
// the next testing trial
// Display test instructions if they haven't been viewed already
while (levels.Count != numlevel)
{
int randNum = UnityEngine.Random.Range(1, numlevel+1);
//Debug.Log(randNum + " = generated");
if (levels.Add(randNum))
{
nextLevel = randNum + 8;
Debug.Log("Trial level: " + randNum + " picked");
Debug.Log(levels.Count);
if (levels.Count == numlevel)
{
OFT_COMPLETE = true;
nextLevel = 37; // lEVEL 37 IS INSTRUCTIONS COMPLETE.
}
break;
}
}
}
else if (learnTrialsCompleted && !practiceTrialsCompleted && practiceInstructionsViewed)
{
nextLevel = practiceTrials + 4;
Debug.Log("Practice Level: " + (nextLevel - 4) + " picked");
practiceTrials += 1;
if (practiceTrials == 5)
{
practiceTrialsCompleted = true;
}
}
else if(instructions && !learnTrialsCompleted)
{
// Sequentially go through each of the four learning trials before beginning
// the testing phase
nextLevel = learnTrials;
Debug.Log("Learn level: " + nextLevel + " picked");
learnTrials += 1;
if (learnTrials == 5)
{
learnTrialsCompleted = true;
}
}
else
{
if (!testInstructionsViewed && practiceInstructionsViewed && instructions)
{
nextLevel = 36;
Debug.Log("Test Instructions");
}
else if (!testInstructionsViewed && !practiceInstructionsViewed && instructions)
{
nextLevel = 35;
Debug.Log("Practice Instructions");
}
else
{
nextLevel = 34;
Debug.Log("Instructions");
}
}
}
void Awake()
{
if (!created)
{
DontDestroyOnLoad(this.gameObject);
created = true;
Debug.Log("Awake: " + this.gameObject);
}
}
// Update is called once per frame
void Update()
{
// If the current scene is Instructions and the participant presses ENTER, move on to the next scene (Learn Trial 01)
if (Input.GetKeyDown(KeyCode.Return))
{
if (!instructions && SceneManager.GetActiveScene().name == "Instructions")
{
instructions = true;
NextScene();
}
else if (!testInstructionsViewed && SceneManager.GetActiveScene().name == "Instructions Test")
{
testInstructionsViewed = true;
NextScene();
}
else if (!practiceInstructionsViewed && SceneManager.GetActiveScene().name == "Instructions Practice")
{
practiceInstructionsViewed = true;
NextScene();
}
}
}
public void StartPause()
{
StartCoroutine(PauseGame());
}
public IEnumerator PauseGame()
{
SceneManager.LoadScene("Fixation");
Debug.Log("SHOOT");
yield return new WaitForSeconds(3);
SceneManager.LoadScene(nextLevel);
}
public void NextScene()
{
LevelPick();
StartPause();
StreamWriter writelevel = File.AppendText(FILE_NAME);
writelevel.WriteLine("level " + nextLevel + " loaded");
writelevel.Close();
StreamWriter writelevelobj = File.AppendText(OBJ_FILE_NAME);
writelevelobj.WriteLine("level " + nextLevel + " loaded");
writelevelobj.Close();
if (nextLevel == currentLevel)
{
TipboxManager.text_tip = "YOU ARE DONE. PRESS ESC TO EXIT PILOT TEST.";
} else
{
currentLevel = nextLevel;
TipboxManager.text_tip = "";
if (currentLevel >= 5 && currentLevel <= 8) { TipboxManager.text_tip = "*** Go to where you believe the target is! ***"; }
}
startTime = Time.time;
if (ParticipantLog.trialPhase != 3)
{
ParticipantLog.trialPhase = 1;
}
LogManager.newTrial = true;
}
}