// Use this for initialization void Awake() { base.Setup(GameManager.SessionType.Inhibition); inhibStimulus = GameObject.Find("Stimulus"); //Preform the read in to get the events events = csv.ReadInSession(); //Generate the practice events generatePractice(); //If the read in failed, generate the base events if (events == null) { events = new List <EventStats>(); NeuroLog.Log("Generating Random list of events"); generateEvents(); } randomizeEvents(); //Start the game StartCoroutine("runSession"); }
// Use this for initialization void Awake() { base.Setup(GameManager.SessionType.Stopping); stoppingStimulus = GameObject.Find("Stimulus"); stoppingStimulus.renderer.material.color = new Color(.125f, .5f, 0, 1); stimPositions = new Vector2[4] { new Vector2(-15, 10), new Vector2(5, 5), new Vector2(15, -10), new Vector2(-10, -5) }; //Preform the read in to get the events events = csv.ReadInSession(); //Generate the practice events generatePractice(); //If the read in failed, generate the base events if (events == null) { events = new List <EventStats>(); NeuroLog.Log("Generating Random list of events"); generateEvents(); } randomizeEvents(); //Start the game StartCoroutine("runSession"); }
// Use this for initialization void Awake() { base.Setup(GameManager.SessionType.Spatial); //Hide all the balls foreach (GameObject g in dots) { g.renderer.enabled = false; g.renderer.material.color = Color.blue; } //Read in the events events = csv.ReadInSession(); //Generate the practice events generatePractice(); //If there was an error reading in the events, generate the basic set if (events == null) { events = new List <EventStats>(); NeuroLog.Log("Generating Random list of events"); generateEvents(); } randomizeEvents(); //Start the game StartCoroutine("runSession"); }
public void OnClick() { if (response != null) { response(gameObject); } else { NeuroLog.Debug("Response method is null"); } }
// Use this for initialization void Awake() { goodResponse = false; base.Setup(GameManager.SessionType.Associate); //Set the num of each stimuli target.Num = 0; for (int i = 0; i < stimuli.Count; i++) { stimuli[i].Num = i + 1; } box.Reset(); //Reset the objects orientation/positions target.Reset(); foreach (AssociateObject aO in stimuli) { aO.Reset(); } //Read in the event events = csv.ReadInSession(); //If read in failed, generate basic list of events if (events == null) { events = new List <EventStats>(); generateEvents(); randomizeCorrectChoice(); randomizeEvents(); NeuroLog.Log("Generating Random events"); } int tNum = PlayerPrefs.GetInt("-currentTask"); if (tNum == 1 || tNum == 0) { generatePractice(); } else { practicing = false; practice = new List <EventStats>(); } //Start the game StartCoroutine("runSession"); }
//Make sure there is at least one sub division public bool SetupPlayersCSV(TextReader reader) { try{ using (CsvReader csv = new CsvReader(reader, true)){ while (csv.ReadNextRecord()) { Child c = new Child(); c.Cluster = csv["cluster"]; c.ID = csv["childID"]; int lastcompleted = -1; int.TryParse(csv["lastcompleted"], out lastcompleted); if (c.lastCompleted < 0) { NeuroLog.Log("Child " + c.ID + "(" + c.Cluster + ") has an invalid value for last Completed. Needs to be between 0-7."); } else { c.lastCompleted = lastcompleted; demographics.Add(c); } } } } catch (Exception e) { NeuroLog.Log(e.Message); return(false); } //Good Exit, found at least one subdivision if (demographics.Count > 1) { return(true); } else { return(false); } }
//Main Method protected override IEnumerator runSession() { //Run the tutorial yield return(StartCoroutine(runTutorial())); //Show Practice card yield return(StartCoroutine(showTitle("Practice", 3))); //generate a practice event generatePractice(); state = GameState.Delay; //Loop til all the events are done while (currentEventNum < numTrials) { //Determine how long the player has based on if its a practice or real trial float endTime = 180; if (practicing) { endTime = 30; } else { arrow.SetActive(true); } //Either setup the set positions of the objects, or randomize it if (CurrentEvent.Objects.Count > 0) { setupPositions(); } else { randomizePositions(); } yield return(new WaitForSeconds(.5f)); screen.enabled = false; state = GameState.Probe; startTime = Time.time; //Loop until the skip arrow is pressed, the player gets all the stars, or the time limit is reached while (Time.time - startTime < endTime && skipTrial == false && CurrentEvent.NumGoodTouches < CurrentEvent.NumLittleStars) { yield return(new WaitForFixedUpdate()); } state = GameState.Delay; //Record how the trial ended if (skipTrial) { CurrentEvent.Duration = Time.time - startTime; CurrentEvent.EndCondition = "Skipped"; NeuroLog.Log("Skipped"); } else if (CurrentEvent.NumGoodTouches >= CurrentEvent.NumLittleStars) { CurrentEvent.Duration = Time.time - startTime; CurrentEvent.EndCondition = "Completed"; NeuroLog.Log("Completed"); yield return(new WaitForSeconds(.25f)); } else { NeuroLog.Log("TimedOut"); CurrentEvent.Duration = endTime; CurrentEvent.EndCondition = "TimedOut"; } //Hide the arrow arrow.SetActive(false); screen.enabled = true; skipTrial = false; //Get the next trial nextEvent(); if (currentEventNum % 3 == 0) { for (int i = 1; i < materials.Length; i++) { materials[i].color = Color.black; } } else if (currentEventNum % 3 == 1) { for (int i = 1; i < materials.Length; i++) { if (i % 2 == 0) { materials[i].color = new Color(.6078f, .7255f, .3529f); } else { materials[i].color = new Color(.4980f, .3922f, .6313f); } } } else if (currentEventNum % 3 == 2) { for (int i = 1; i < materials.Length; i++) { if (i % 2 == 0) { materials[i].color = new Color(.9216f, .7089f, .7089f); } else { materials[i].color = new Color(.2157f, .7843f, .2157f); } } } //If we reached the end of the practice list, check to see if the player passed if (practicing && currentPractice >= practice.Count) { practiceSessionCount++; int numCorrect = 0; for (int i = currentPractice - 1; i < currentPractice; i++) { if (practice[i].respondedCorrectly()) { numCorrect += 1; } } //If the player correct did the practice trial, or has tried 4 times, continue on if (numCorrect >= 1f || practiceSessionCount >= 4) { NeuroLog.Log("Continuing to MainSession"); yield return(StartCoroutine(showTitle("Test", 3))); border.SetActive(false); practicing = false; } else { NeuroLog.Log("Redo Practice"); yield return(StartCoroutine(runTutorial())); yield return(StartCoroutine(showTitle("Practice", 3))); generatePractice(); } } } gameOver = true; //Write out the Log file csv.WriteOut(true); yield return(StartCoroutine(showTitle("Session Over", 3))); NeuroLog.Log("GAME OVER, Returning to menu"); //Return to the menu Application.LoadLevel("menu"); }
// Use this for initialization void Awake() { skipTrial = false; base.Setup(GameManager.SessionType.Star); //Hide the arrow arrow = GameObject.Find("next"); arrow.SetActive(false); for (int i = 1; i < materials.Length; i++) { materials[i].color = Color.black; } //Read in the event events = csv.ReadInSession(); //If read in failed, generate basic list of events if (events == null) { events = new List <EventStats>(); NeuroLog.Log("Generating Random events"); numTrials = 2; for (int i = 0; i < numTrials; i++) { StarEvent eS = new StarEvent(); eS.NumLittleStars = 34; eS.NumBigStars = 31; eS.NumTriangles = 7; eS.NumDots = 6; events.Add(eS); } } else { numTrials = events.Count; } //Find the max number of objects we'll need int maxTri = 2; int maxDot = 2; int maxLS = 3; int maxBS = 5; foreach (StarEvent sE in events) { if (sE.NumBigStars > maxBS) { maxBS = sE.NumBigStars; } if (sE.NumLittleStars > maxLS) { maxLS = sE.NumLittleStars; } if (sE.NumDots > maxDot) { maxDot = sE.NumDots; } if (sE.NumTriangles > maxTri) { maxTri = sE.NumTriangles; } } //Have the game generate the maximum amount of objects needed for this session generateObjects(maxLS, maxBS, maxDot, maxTri); //Start the game StartCoroutine("runSession"); }
//Main method of the game protected override IEnumerator runSession() { //Show the tutorial yield return(StartCoroutine(runTutorial())); //Show Practice screen yield return(StartCoroutine(showTitle("Practice", 3))); screen.enabled = false; //Main Session while (currentEventNum < events.Count) { if (CurrentEvent.Go) { stoppingStimulus.renderer.material.color = new Color(.125f, .5f, 0, 1); } else { stoppingStimulus.renderer.material.color = new Color(1, .5f, 0); } if (practicing) { if (CurrentEvent.Dot == 1) { stoppingStimulus.transform.position = new Vector3(-20, -3.5f, 10); } else if (CurrentEvent.Dot == 2) { stoppingStimulus.transform.position = new Vector3(20, -3.5f, 10); } else if (CurrentEvent.Dot == 3) { stoppingStimulus.transform.position = new Vector3(-20, -3.5f, -10); } else { stoppingStimulus.transform.position = new Vector3(20, -3.5f, -10); } } else { stoppingStimulus.transform.position = new Vector3(stimPositions[CurrentEvent.Dot - 1].x, -3.5f, stimPositions[CurrentEvent.Dot - 1].y); } stoppingStimulus.renderer.enabled = true; startTime = Time.time; float currentTime = 0; //bool changed = false; state = GameState.Probe; /* * if(!CurrentEvent.Go){ * CurrentEvent.TurningTime = (avgResponseTime/2f); * }*/ //Wait for either the player's response or the time limit while (CurrentEvent.Response == null && currentTime < 1f) { currentTime += Time.deltaTime; yield return(new WaitForFixedUpdate()); } //ITI, black screen state = GameState.ITI; //screen.enabled = true; stoppingStimulus.renderer.enabled = false; if (currentTime >= 1f) { CurrentEvent.TimedOut = true; } /* * if(CurrentEvent.Response == null && !practicing){ * if(!CurrentEvent.Go){ * avgResponseTime+=.025f; * Mathf.Clamp(avgResponseTime,0,1.4f); * } * } * //Calculate the avgResponseTime of the first 8 * if(currentEventNum==7){ * avgResponseTime = 0; * for(int i = 0;i<8;i++){ * if(((StoppingEvent)events[i]).Response != null) * avgResponseTime += ((StoppingEvent)events[i]).Response.ResponseTime; * else avgResponseTime +=1f; * } * * avgResponseTime = avgResponseTime/8; * } */ yield return(new WaitForSeconds(.1f)); //Get the next event nextEvent(); //If we reached the end of the practice list, check to see if the player passed if (practicing && currentPractice >= practice.Count) { //Count the nummber of correct responses int numCorrect = 0; for (int i = currentPractice - 4; i < currentPractice; i++) { if (practice[i].respondedCorrectly()) { numCorrect += 1; } } NeuroLog.Log("Total Correct Responded: " + numCorrect); //If the numCorrect is greater than 5, or played the practice 4 times, continue on if (numCorrect >= 4 || practiceSessionCount >= 3) { NeuroLog.Log("Continuing to MainSession"); border.SetActive(false); yield return(StartCoroutine(showTitle("Test", 3))); practicing = false; } //Otherwise retry the practice else { practiceSessionCount++; NeuroLog.Log("Redo Practice"); generatePractice(); yield return(StartCoroutine(runTutorial())); yield return(StartCoroutine(showTitle("Practice", 3))); } } } gameOver = true; //Writeout csv.WriteOut(true); //SessionTitle screen yield return(StartCoroutine(showTitle("Session Over", 3))); Debug.Log("GAME OVER, Returning to menu"); //Return to menu Application.LoadLevel("menu"); }
//Main method protected override IEnumerator runSession() { //Run tutorial yield return(StartCoroutine(runTutorial())); //Show Practice Screen yield return(StartCoroutine(showTitle("Practice", 3))); //Main Session while (currentEventNum < events.Count) { //Encoding //Display the dots state = GameState.Encoding; foreach (int i in CurrentEvent.Dots) { dots[i - 1].renderer.enabled = true; } screen.enabled = false; yield return(new WaitForSeconds(2f)); //Delay state = GameState.Delay; screen.material.color = Color.white; screen.enabled = true; foreach (GameObject g in dots) { g.renderer.enabled = false; } startTime = CurrentEvent.Delay + Time.time; yield return(new WaitForSeconds(CurrentEvent.Delay)); float timeLimit = 3; if (practicing) { timeLimit = 4; } //Probe screen.material.color = new Color(.2f, .2f, .2f, 1); state = GameState.Probe; float currentTime = 0; while (CurrentEvent.Responses.Count < CurrentEvent.Dots.Count && currentTime < timeLimit) { currentTime += Time.deltaTime; yield return(new WaitForFixedUpdate()); } if (currentTime >= timeLimit) { CurrentEvent.TimedOut = true; } if (CurrentEvent.Responses.Count == CurrentEvent.Dots.Count) { yield return(new WaitForSeconds(.1f)); } //ITI state = GameState.ITI; screen.material.color = Color.black; screen.enabled = true; yield return(new WaitForSeconds(.5f)); nextEvent(); //If the player is still practicing, and reached the end of the practice list check to see if the player did good enough to move on if (practicing && currentPractice >= practice.Count) { practiceSessionCount++; int numCorrect = 0; for (int i = currentPractice - 6; i < currentPractice; i++) { if (practice[i].respondedCorrectly()) { numCorrect += 1; } } NeuroLog.Log("Total Correct Responded: " + numCorrect); //If at least 3 correct, or 4 tries already, move on to the test phase if (numCorrect >= 3 || practiceSessionCount >= 4) { NeuroLog.Log("Continuing to MainSession"); yield return(StartCoroutine(showTitle("Test", 3))); border.SetActive(false); practicing = false; } //Otherwise retry practice else { NeuroLog.Log("Redo Practice"); generatePractice(); yield return(StartCoroutine(runTutorial())); yield return(StartCoroutine(showTitle("Practice", 3))); } } } gameOver = true; //Writeout the log file csv.WriteOut(true); yield return(StartCoroutine(showTitle("Session Over", 3))); Debug.Log("GAME OVER, Returning to menu"); //Return to the menu Application.LoadLevel("menu"); }
//Reset PlayerPrefs and shut down private void resetDevice(GameObject o) { NeuroLog.Log("Resetting the device"); bool testingMode = true; if (PlayerPrefs.HasKey("-testingMode")) { if (PlayerPrefs.GetString("-testingMode") == "false") { testingMode = false; } } //If the player completed all the tasks and it's not a custom ID if (!customID && !testingMode) { try{ string path = Path.Combine(CsvManager.PlayerSpecificPath, "players.csv"); //Make sure the player file is available if (File.Exists(path)) { //Get the lines from the csv file string[] lines = System.IO.File.ReadAllLines(path); //Get the cluster and id strings string cluster = PlayerPrefs.GetString("-cluster"); string ID = PlayerPrefs.GetString("-childID"); int playerLine = -1; //Loop through the lines until we find the matching line for (int i = 0; i < lines.Length; i++) { string[] values = lines[i].Split(','); if (values[0] == cluster && values[1] == ID) { playerLine = i; break; } } if (playerLine == -1) { NeuroLog.Log("Could not find the player {0}:{1} in the players file, adding it", cluster, ID); using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(cluster + "," + ID + "," + latestTask); } } else { lines[playerLine] = cluster + "," + ID + "," + latestTask; System.IO.File.WriteAllLines(path, lines); } } else { NeuroLog.Log("Unable to find the player file to update the player's status"); } } catch (UnityException e) { NeuroLog.Log("Unable to update the player's status:\n" + e.Message); } } //Delete all saved player prefs PlayerPrefs.DeleteAll(); //Quit Application.Quit(); }
//If a task button was pressed, find out what game type it is then start the game private void beginTask(GameObject o) { //String the fileName string fileName = selectedTask + ".csv"; //Get the taskNumber int num = int.Parse(selectedTask.Replace("task", "")); TextReader sR; try{ if (File.Exists(Path.Combine(CsvManager.SessionFilesPath, fileName))) { NeuroLog.Debug("Loading session file from {0}", fileName); sR = new StreamReader(Path.Combine(CsvManager.SessionFilesPath, fileName)); } else { NeuroLog.Log("Loading bundled session file {0}", fileName); TextAsset sessionData = Resources.Load("session_files/" + fileName) as TextAsset; sR = new StringReader(sessionData.text); } } catch (UnityException e) { NeuroLog.Error("Unable to load task file:\n" + e.Message); return; } PlayerPrefs.SetInt("-currentTask", num); //Check the headers to make sure its the right type of file using (CsvReader csv = new CsvReader(sR, true)){ List <string> headers = new List <string>(csv.GetFieldHeaders()); for (int i = 0; i < headers.Count; i++) { headers[i] = headers[i].ToLower(); } if (headers.Contains("dots") && headers.Contains("delay")) { NeuroLog.Log("Loading Spatial game"); Application.LoadLevel("spatial"); } else if (headers.Contains("side") && headers.Contains("color")) { NeuroLog.Log("Loading Inhibition game"); Application.LoadLevel("inhibition"); } else if (headers.Contains("blocknum") && headers.Contains("type") && headers.Contains("position") && headers.Contains("rotation")) { NeuroLog.Log("Loading Star game"); Application.LoadLevel("star"); } else if (headers.Contains("blocknum") && headers.Contains("dot")) { NeuroLog.Log("Loading Implicit game"); Application.LoadLevel("implicit"); } else if (headers.Contains("go") && headers.Contains("dot")) { NeuroLog.Log("Loading Stopping game"); Application.LoadLevel("stopping"); } else if (headers.Contains("target") && headers.Contains("stimuli")) { NeuroLog.Log("Loading Associate game"); Application.LoadLevel("associate"); } else { NeuroLog.Log("Listed headers in task " + num + "do not match up with any of the current programs"); } } }
//Main method of the game protected override IEnumerator runSession() { //Show the tutorial yield return(StartCoroutine(runTutorial())); //Show Practice screen if (practicing) { yield return(StartCoroutine(showTitle("Practice", 3))); } else { yield return(StartCoroutine(showTitle("Test", 3))); border.SetActive(false); } screen.enabled = false; //Main Session while (currentEventNum < events.Count) { //Probe //Set up the stimuli if (CurrentEvent.TargetImage > 0) { target.renderer.material.mainTexture = images[CurrentEvent.TargetImage - 1]; } else { int num = (CurrentEvent.TargetImage * -1) - 1; target.renderer.material.mainTexture = pracImages[num]; } for (int i = 0; i < 4; i++) { if (CurrentEvent.Stimuli[i] > 0) { stimuli[i].renderer.material.mainTexture = images[CurrentEvent.Stimuli[i] - 1]; } else { int num = (CurrentEvent.Stimuli[i] * -1) - 1; stimuli[i].renderer.material.mainTexture = pracImages[num]; } } yield return(StartCoroutine(startEvent())); startTime = Time.time; state = GameState.Probe; //Wait for either the player's response or the time limit while (!goodResponse) { yield return(new WaitForFixedUpdate()); } //ITI, dancing objects state = GameState.ITI; goodResponse = false; int correct = CurrentEvent.Stimuli.IndexOf(getMatchingNum(CurrentEvent.TargetImage)); yield return(StartCoroutine(endEvent(correct))); //Get the next event nextEvent(); yield return(new WaitForSeconds(.25f)); //If we reached the end of the practice list, check to see if the player passed if (practicing && currentPractice >= practice.Count) { //Count the nummber of correct responses practiceSessionCount++; int numCorrect = 0; for (int i = currentPractice - 4; i < currentPractice; i++) { if (practice[i].respondedCorrectly()) { numCorrect += 1; } } NeuroLog.Log("Total Correct Responded: " + numCorrect); //If the numCorrect is greater than 5, or played the practice 4 times, continue on if (numCorrect >= 3 || practiceSessionCount >= 4) { NeuroLog.Log("Continuing to MainSession"); border.SetActive(false); yield return(StartCoroutine(showTitle("Test", 3))); practicing = false; } //Otherwise retry the practice else { NeuroLog.Log("Redo Practice"); generatePractice(); yield return(StartCoroutine(runTutorial())); yield return(StartCoroutine(showTitle("Practice", 3))); } } } gameOver = true; //Writeout csv.WriteOut(true); //SessionTitle screen yield return(StartCoroutine(showTitle("Session Over", 3))); Debug.Log("GAME OVER, Returning to menu"); //Return to menu Application.LoadLevel("menu"); }
//Used to read in void LateUpdate() { if (Input.GetKeyDown(KeyCode.Escape)) { if (Screen.fullScreen) { int width = Screen.currentResolution.width - 200; int height = Screen.currentResolution.height; height = Mathf.RoundToInt(width / 1.77777778f); Screen.SetResolution(width, height, false); } else { int width = 1366; int height = 768; Screen.SetResolution(width, height, true); } } if (!gameOver && touching) { if (dragPoints.Count == 0) { dragPoints.Add(touchPos); } else { if (Vector3.Distance(dragPoints[dragPoints.Count - 1], touchPos) > 50) { if (dragPoints.Count == 1) { dragPoints.Add(touchPos); activeSlope = Vector3.Angle(new Vector3(1, 0, 0), new Vector3((dragPoints[dragPoints.Count - 1].x - dragPoints[dragPoints.Count - 2].x), (dragPoints[dragPoints.Count - 1].y - dragPoints[dragPoints.Count - 2].y), 0)); } else { float newAngle = Vector3.Angle(new Vector3(1, 0, 0), new Vector3((touchPos.x - dragPoints[dragPoints.Count - 1].x), (touchPos.y - dragPoints[dragPoints.Count - 1].y), 0)); if (Mathf.Abs(activeSlope - newAngle) < 60f) { if (dragPoints.Count == 4) { if (Vector3.Distance(dragPoints[2], dragPoints[3]) < (Vector3.Distance(dragPoints[0], dragPoints[1]) + 50)) { dragPoints[3] = touchPos; } } else { dragPoints[dragPoints.Count - 1] = touchPos; } } else { if (dragPoints.Count < 4) { dragPoints.Add(touchPos); activeSlope = Vector3.Angle(new Vector3(1, 0, 0), new Vector3((dragPoints[dragPoints.Count - 1].x - dragPoints[dragPoints.Count - 2].x), (dragPoints[dragPoints.Count - 1].y - dragPoints[dragPoints.Count - 2].y), 0)); } } //If there are 4 points if (dragPoints.Count == 4) { //Make sure the first and last line have about the same length (Margin of 100 pixels) if (Mathf.Abs(Vector3.Distance(dragPoints[0], dragPoints[1]) - Vector3.Distance(dragPoints[2], dragPoints[3])) <= 100) { //The 1st line of the Z (first drawn) float angOne = Vector3.Angle(new Vector3(1, 0, 0), new Vector3((dragPoints[1].x - dragPoints[0].x), (dragPoints[1].y - dragPoints[0].y), 0)); if ((dragPoints[1].y - dragPoints[0].y) / (dragPoints[1].x - dragPoints[0].x) < 0) { angOne *= -1; } //The 3rd line of the Z (last drawn) float angTwo = Vector3.Angle(new Vector3(1, 0, 0), new Vector3((dragPoints[3].x - dragPoints[2].x), (dragPoints[3].y - dragPoints[2].y), 0)); if ((dragPoints[3].y - dragPoints[2].y) / (dragPoints[3].x - dragPoints[2].x) < 0) { angTwo *= -1; } //The middle line of the Z float angSlash = Vector3.Angle(new Vector3(1, 0, 0), new Vector3((dragPoints[1].x - dragPoints[2].x), (dragPoints[1].y - dragPoints[2].y), 0)); if ((dragPoints[1].y - dragPoints[2].y) / (dragPoints[1].x - dragPoints[2].x) < 0) { angSlash *= -1; } //Make sure the first and last line are draw at about the same angle(margin of 30'), //and if the first and middle line are not given the sameish angle(margin of 10'), then its a Z if (Mathf.Abs(angOne - angTwo) < 30 && Mathf.Abs(angOne - angSlash) > 10) { //Delete the current task PlayerPrefs.DeleteKey("-currentTask"); NeuroLog.Debug("READ 'Z' SWIPE, HALTING TASK"); //Write out the incompleted csv csv.WriteOut(false); //Go back to the menu Application.LoadLevel("menu"); } } } } } /* * //For debuging, will show swipe in scene screen * Color c = Color.white; * for(int i=0;i<dragPoints.Count;i++){ * if(i==1) c = Color.red; * else if(i==2) c = Color.green; * else if (i == 3) c = Color.blue; * * if(i+ 1 == dragPoints.Count){ * Debug.DrawLine(new Vector3(((dragPoints[i].x/Screen.width)*53.4 - 26.7f), 8,((dragPoints[i].y/Screen.height)*30 - 15f)), * new Vector3(((touchPos.x/Screen.width)*53.4 - 26.7f), 8,((touchPos.y/Screen.height)*30 - 15f)), c); * } * else{ * Debug.DrawLine(new Vector3(((dragPoints[i].x/Screen.width)*53.4 - 26.7f), 8,((dragPoints[i].y/Screen.height)*30 - 15f)), * new Vector3(((dragPoints[i+1].x/Screen.width)*53.4 - 26.7f), 8,((dragPoints[i+1].y/Screen.height)*30 - 15f)), c); * } * } */ } } //If the player isn't touching the screen, reset the dragPoints else if (dragPoints.Count > 0) { dragPoints = new List <Vector3>(); activeSlope = 0; } }
//If a button is pressed public void buttonPressed(GameObject gO) { //If the config has been saved, quit once the button is pressed if (configSaved) { NeuroLog.Log("Exiting Now"); Application.Quit(); } //If the config hasn't been saved else { //Set up the task statuses if (testingCheckbox.isChecked) { PlayerPrefs.SetString("-testingMode", "true"); PlayerPrefs.SetString("-t1", "true"); PlayerPrefs.SetString("-t2", "true"); PlayerPrefs.SetString("-t3", "true"); PlayerPrefs.SetString("-t4", "true"); PlayerPrefs.SetString("-t5", "true"); PlayerPrefs.SetString("-t6", "true"); PlayerPrefs.SetString("-t7", "true"); } else { PlayerPrefs.SetString("-testingMode", "false"); //Get the last completed of the player int lastCompleted = 0; foreach (Child c in demographics) { if (playerSelector.SelectedPlayer == c.ID && playerSelector.SelectedCluster == c.Cluster) { lastCompleted = c.lastCompleted; } } //Save the t values for (int i = 1; i < 8; i++) { if (lastCompleted < i) { PlayerPrefs.SetString("-t" + i, "false"); } else { PlayerPrefs.SetString("-t" + i, "true"); } } } if (english.isChecked) { PlayerPrefs.SetString("-language", "english"); } else { PlayerPrefs.SetString("-language", "spanish"); } string name = ""; //Save the player's info if (testName == "") { name = playerSelector.SelectedPlayer.Trim(); PlayerPrefs.SetString("-childID", playerSelector.SelectedPlayer); PlayerPrefs.SetString("-customID", "f"); PlayerPrefs.SetString("-cluster", playerSelector.SelectedCluster); } else { //testName = testName.Replace(" ", ""); PlayerPrefs.SetString("-childID", testName); PlayerPrefs.SetString("-customID", "t"); PlayerPrefs.SetString("-cluster", "n/a"); } using (StreamWriter writer = new StreamWriter(Path.Combine(CsvManager.PlayerSpecificPath, name + "_" + System.Environment.MachineName + "_Criterion.csv"))){ writer.WriteLine("TaskNum,CriterionScore,NumofPractice,NumofEvents,AccuracyofPresented,AccuracyofResponses,NumResponsesBasal"); for (int i = 0; i < 8; i++) { writer.WriteLine(i + ",0,.,.,.,.,."); } } if (currentlyEnglish) { message.text = "Config info saved"; buttonText.text = "CLOSE"; } else { message.text = "La configuración ha sido guardada"; buttonText.text = "CERRAR"; confirmBackground.transform.localScale = new Vector3(225, 60, 1); } configSaved = true; english.gameObject.SetActive(false); spanish.gameObject.SetActive(false); testingCheckbox.gameObject.SetActive(false); playerSelector.gameObject.SetActive(false); keyboard.gameObject.SetActive(false); testInput.gameObject.SetActive(false); customIDButton.gameObject.SetActive(false); quitButton.gameObject.SetActive(false); testingLabel.enabled = false; } }
// Use this for initialization void Start() { cam = Camera.main; currentlyEnglish = true; if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { windowsTab = true; testInput.collider.enabled = false; } demographics = new List <Child>(); //Resize the window to fit the monitor if (!Screen.fullScreen) { Screen.SetResolution(1366, 768, true); } //Have the static xmlmanager check to make sure the folders are properly set up if (!CsvManager.CheckFolders()) { //If a folder(s) is missing, exit out of the game NeuroLog.Error("Unable to start program due to missing folder"); Application.Quit(); } //Remove any saved previously saved scene PlayerPrefs.DeleteKey("-currentTask"); needConfig = false; bool foundFile = true; playerSelector.gameObject.SetActive(true); keyboard.gameObject.SetActive(false); //Hide all the elements on the screen until were sure the files are set up english.gameObject.SetActive(false); spanish.gameObject.SetActive(false); playerSelector.gameObject.SetActive(false); testingCheckbox.gameObject.SetActive(false); testingLabel.enabled = false; confirmButton.gameObject.SetActive(false); confirmButton.GetComponent <ButtonResponder>().response = buttonPressed; customIDButton.GetComponent <ButtonResponder>().response = showInputField; customIDButton.gameObject.SetActive(false); //Set up the quit button, it should be the only thing on the screen at the start quitButton.gameObject.SetActive(true); quitButton.response = quitbuttonPressed; back.response = showPlayerSelector; message.enabled = false; background.color = Color.black; TextReader reader = null; //Try to load the players file. If it fails, exit out try{ //Try on Dropbox string fn = Path.Combine(CsvManager.PlayerSpecificPath, playersFile); NeuroLog.Debug("Attempting to read from Dropbox folder: " + fn); reader = new StreamReader(fn); } catch { NeuroLog.Debug("Unable to find dropbox player file, loading bundled one"); //Try local bundle if not on dropbox try{ TextAsset sessionData = Resources.Load(playersFile) as TextAsset; reader = new StringReader(sessionData.text); } catch { NeuroLog.Error("Unable to find players file"); foundFile = false; } } //If the program found the file if (foundFile) { string p = PlayerPrefs.GetString("-childID"); string customID = PlayerPrefs.GetString("-customID"); //If there is no player saved in PlayerPrefs, signal that we need to config the device if (p == "") { needConfig = true; NeuroLog.Log("No player set to the device."); } else if (customID == "t") { needConfig = false; NeuroLog.Log("Using customID Player"); } //If the program needs to be configured, make all the GUI elements appear if (needConfig) { //Remove any previously set brightness value PlayerPrefs.DeleteKey("-ambience"); //Set up the players file if (SetupPlayersCSV(reader)) { playerSelector.setupTab(this, demographics); playerSelector.gameObject.SetActive(true); customIDButton.gameObject.SetActive(true); testingCheckbox.gameObject.SetActive(true); english.gameObject.SetActive(true); spanish.gameObject.SetActive(true); background.color = Color.white; } else { NeuroLog.Error("Failed to initialize config scene."); message.text = "Error! Unable to Run Config Program!"; message.enabled = true; } } //If the program doesn't need to be configured just go to the next scene else { if (!PlayerPrefs.HasKey("-language")) { PlayerPrefs.SetString("-language", "english"); } Application.LoadLevel("menu"); } } //Tell the player the file was unable to be loaded else { NeuroLog.Error("Failed to initialize config scene."); needConfig = false; message.text = "Error! Unable to Run Config Program!"; message.enabled = true; } }
//Main method of the game protected override IEnumerator runSession() { //Show the tutorial yield return(StartCoroutine(runTutorial())); //Show Practice screen yield return(StartCoroutine(showTitle("Practice", 3))); //Main Session while (currentEventNum < events.Count) { //Probe //Set up the ball's color if (CurrentEvent.DotColor == "yellow") { inhibStimulus.renderer.material = yellow; } else { inhibStimulus.renderer.material = stripesPurple; } //Set up the ball's position if (CurrentEvent.Side == 'l') { inhibStimulus.transform.position = new Vector3(-13.25f, -6f, 0); } else { inhibStimulus.transform.position = new Vector3(13.25f, -6f, 0); } screen.enabled = false; startTime = Time.time; float currentTime = 0; state = GameState.Probe; //Wait for either the player's response or the time limit while (CurrentEvent.Response == null && currentTime < 2.5f) { currentTime += Time.deltaTime; yield return(new WaitForFixedUpdate()); } if (currentTime >= 2.5f) { CurrentEvent.TimedOut = true; } if (CurrentEvent.Response != null) { yield return(new WaitForSeconds(.1f)); } //ITI, black screen state = GameState.ITI; screen.enabled = true; yield return(new WaitForSeconds(.5f)); //Get the next event nextEvent(); //If we reached the end of the practice list, check to see if the player passed if (practicing && currentPractice >= practice.Count) { //Count the nummber of correct responses practiceSessionCount++; int numCorrect = 0; for (int i = currentPractice - 7; i < currentPractice; i++) { if (practice[i].respondedCorrectly()) { numCorrect += 1; } } NeuroLog.Log("Total Correct Responded: " + numCorrect); //If the numCorrect is greater than 5, or played the practice 4 times, continue on if (numCorrect >= 5 || practiceSessionCount >= 4) { NeuroLog.Log("Continuing to MainSession"); border.SetActive(false); yield return(StartCoroutine(showTitle("Test", 3))); practicing = false; } //Otherwise retry the practice else { NeuroLog.Log("Redo Practice"); generatePractice(); yield return(StartCoroutine(runTutorial())); yield return(StartCoroutine(showTitle("Practice", 3))); } } } gameOver = true; //Writeout csv.WriteOut(true); //SessionTitle screen yield return(StartCoroutine(showTitle("Session Over", 3))); Debug.Log("GAME OVER, Returning to menu"); //Return to menu Application.LoadLevel("menu"); }