// Update is called once per frame void Update() { if (!studyComplete) { switch (currentState) { case studyState_t.Waiting4StudyContent: studyState.text = "Study State: waiting for map study to start."; studyAction.text = "Press 'space' to generate maps and setup study."; mapNumText.text = "Map Num: " + currMapIndex.ToString(); trialNumText.text = "Trial Num: " + currTargetIndex.ToString(); currentTargetText.text = "Target: "; // turn off mouse if (staticCondition) { ShapeCastObject.useMouse = false; } // if space is pressed then get ready to start study if (Input.GetKeyDown(KeyCode.Space)) { // Create data recorder element mapRecorder = new RecordData(filename + "_mapFile" + "_mapNo_" + mapNum, mapRecorderCols); // generate a map GenerateMap(); // write map to file foreach (GameObject obj in allObjects) { Vector3 objInWorkspacePos = workspace.transform.InverseTransformPoint(obj.transform.position); mapRecorder.addData(currMapIndex.ToString(), obj.name, ((objInWorkspacePos.x * 1000.0f) + 26.0f).ToString(), ((objInWorkspacePos.y * 1000.0f) + 26.0f).ToString(), (objInWorkspacePos.z * 1000.0f).ToString()); } mapRecorder.WriteToFile(); // switch to waiting for trial currentState = studyState_t.Waiting4Trial; // reset trial counter currTargetIndex = 0; // increment map index counter currMapIndex++; } break; case studyState_t.Waiting4Trial: currentTargetText.text = ""; studyState.text = "Study State: waiting for trial to start."; studyAction.text = "Press 'space' to initiate trial."; //Debug.Log("Curr map index: " + currMapIndex + " | curr target index: " + currTargetIndex); // if space bar then get ready to start trial if (Input.GetKeyDown(KeyCode.Space)) { // start timers trialStartTime = Time.time; trialRecordingCounter = 0.0f; // start trial recording list and file trialPos = new List <Vector2>(); posRecorder = new RecordData(filename + "_trialPosData" + "_mapNo_" + mapNum + "_trialNo_" + currTargetIndex, posRecorderCols); // start the map answers recorder mapAnswersRecorder = new RecordData(Directory.GetCurrentDirectory() + "/Assets/Data/" + filename + "_mapAnswers" + "_mapNo_" + mapNum + ".txt", mapAnswersRecorderCols); // set mouse on if (staticCondition) { ShapeCastObject.useMouse = true; } // Set the target text currentTargetText.text = "Target: " + targetObjects[currTargetIndex].name; trialNumText.text = "Trial Num: " + currTargetIndex.ToString(); // increment index for object currTargetIndex++; // change states to during trial currentState = studyState_t.DuringTrial; } break; case studyState_t.DuringTrial: studyState.text = "Study State: trial in progress."; studyAction.text = "Press 'space' when target is reached."; // decrement recording counter trialRecordingCounter -= Time.deltaTime; // if timer is over for recording if (trialRecordingCounter < 0.0f) { // record position data in mm Vector3 shapeInWorkspacePos = workspace.transform.InverseTransformPoint(ShapeDisplayPosObject.transform.position); trialPos.Add(new Vector2(shapeInWorkspacePos.x * 1000.0f, shapeInWorkspacePos.y * 1000.0f)); } // if space bar, then target has been reached if (Input.GetKeyDown(KeyCode.Space)) { // change states to TargetReached currentState = studyState_t.TargetReached; // turn off mouse if (staticCondition) { ShapeCastObject.useMouse = false; } } break; case studyState_t.TargetReached: trialElapsedTime = Time.time - trialStartTime; studyState.text = "Study State: target reached. End of trial."; studyAction.text = "Press 'space' when answer selection has been made."; // show dropdown // targetSelection.gameObject.SetActive(true); // if dropdown selection has been made if (Input.GetKeyDown(KeyCode.Space)) { currentTargetText.text = ""; Debug.Log("Please wait. Writing data to file."); // save data for position and trial answer foreach (Vector2 pos in trialPos) { posRecorder.addData(currMapIndex.ToString(), pos.x.ToString(), pos.y.ToString()); } mapAnswersRecorder.addData((currMapIndex - 1).ToString(), targetObjects[currTargetIndex - 1].name, options[targetSelection.value], trialElapsedTime.ToString()); // write to file for position and for answer posRecorder.WriteToFile(); mapAnswersRecorder.WriteToFileName(); // if there are more trials if (currTargetIndex < targetObjects.Count) { // go back to waiting for trial currentState = studyState_t.Waiting4Trial; } // if there are more maps to see and trials are over else if (currMapIndex < numOfMaps && currTargetIndex >= targetObjects.Count) { // go back to beginning of study currentState = studyState_t.Waiting4StudyContent; } // else if its the last map else if (currMapIndex >= numOfMaps) { // mark end of study studyComplete = true; } // set the dropdown back to inactive targetSelection.gameObject.SetActive(false); } break; } //endswitch } else { studyState.text = "Study State: end of study."; studyAction.text = ""; } }