private void LateUpdate() { if (isPaused && isInAcceptor) { //ANIMATION instructionController.ShrinkInstructions(); instructionController.IsStill(); exampleController.isDoneInstruction = true; isPaused = false; CancelInvoke("CheckForPause"); } else { //if cursor is visible.. if (exampleController.trialType.Contains("rotated") || exampleController.trialType.Contains("clamped") || exampleController.trialType.Contains("aligned")) { //if cursor is paused AND in target if (isPaused && isInTarget) { //disable the tracker script (for the return to home position) trackerHolderObject.GetComponent <PositionRotationTracker>().enabled = false; isPaused = false; isInTarget = false; CancelInvoke("CheckForPause"); targetReached = true; //Destroy old target targetHolderController.DestroyTarget(); //Create homeposition homePosition.SetActive(true); } if (isPaused && isInHome && exampleController.isDoneInstruction) { //Turn off home homePosition.SetActive(false); isInHome = false; //isPaused = false; CancelInvoke("CheckForPause"); //Create random target //Vector3 newTargetPosition = new Vector3(UnityEngine.Random.Range(-0.25f, 0.25f), 0.7f, UnityEngine.Random.Range(0.35f, 0.45f)); //Quaternion targetRotation = new Quaternion(0, 0, 0, 0); //Instantiate(target, exampleController.targetPosition, targetRotation); if (targetReached) { targetReached = false; //start the next trial exampleController.EndAndPrepare(); } else { if (exampleController.trialInBlock != 1 || exampleController.isInstructionTrial == true) { //Create TARGET targetHolderController.InstantiateTarget(); } //enable the tracker script (for the reach to target) trackerHolderObject.GetComponent <PositionRotationTracker>().enabled = true; } } } //if cursor is invisible else { //if cursor is paused if (isPaused && !isInHomeArea) { //disable the tracker script (for the return to home position) trackerHolderObject.GetComponent <PositionRotationTracker>().enabled = false; isPaused = false; isInTarget = false; CancelInvoke("CheckForPause"); //Destroy old target targetHolderController.DestroyTarget(); //Create homeposition homePosition.SetActive(true); // set target reached -- so that a trial can end (in non-noCursor tasks, this happens when people actually reach the target) targetReached = true; } if (isInHome && isPaused && exampleController.isDoneInstruction) { //Turn off home homePosition.SetActive(false); isInHome = false; //isPaused = false; CancelInvoke("CheckForPause"); //Create random target //randomize location of target //Vector3 newTargetPosition = new Vector3(UnityEngine.Random.Range(-0.25f, 0.25f), 0.7f, UnityEngine.Random.Range(0.35f, 0.45f)); //Quaternion targetRotation = new Quaternion(0, 0, 0, 0); //Instantiate(target, exampleController.targetPosition, targetRotation); if (targetReached) { targetReached = false; //start the next trial exampleController.EndAndPrepare(); } else { if (exampleController.trialInBlock != 1 || exampleController.isInstructionTrial == true) { //Create TARGET targetHolderController.InstantiateTarget(); } //enable the tracker script (for the reach to target) trackerHolderObject.GetComponent <PositionRotationTracker>().enabled = true; } } } } }
//START A TRIAL! //call this next one on the "On Trial Begin" event public void StartReachTrial(Trial trial) { //Debug.Log("starting reach trial!"); trialInBlock = trial.numberInBlock; // set isInstruction trial to true when you need to wait for instruction if (trial.numberInBlock == 1 && Convert.ToBoolean(trial.settings["show_instruction"])) { isInstructionTrial = true; } else { isInstructionTrial = false; } // Show instructions when required // If the trial is the first trial in the block if (trial.numberInBlock == 1) { //Set the instruction text to instruction_text instructionTextMesh.text = Convert.ToString(trial.settings["instruction_text"]); // If showInstruction is true if (Convert.ToBoolean(trial.settings["show_instruction"]) == true) { isDoneInstruction = false; Debug.Log("show instruction = true, expanding"); // transition to the big instruction, change the text instructionController.ExpandInstruction(); instructionController.IsStill(); } else if (Convert.ToBoolean(trial.settings["show_instruction"]) == false) { Debug.Log("show instruction = false, doing nothing"); isDoneInstruction = true; } } //Pseudorandom target location if (shuffledTargetList.Count < 1) { if (Convert.ToInt32(trial.settings["target_list_to_use"]) == 1) { shuffledTargetList = new List <int>(targetList_1); } else if (Convert.ToInt32(trial.settings["target_list_to_use"]) == 2) { shuffledTargetList = new List <int>(targetList_2); } shuffledTargetList.Shuffle(); } int targetLocation = shuffledTargetList[0]; //print(targetLocation); //remove the used target from the list shuffledTargetList.RemoveAt(0); //determine Target Position (used by ColliderDetector to instantiate the target) //rotate the target holder (the -90 just needs to be done for some reason..) // here we are casting to a float (explicit conversion) targetYOffset = (float)Convert.ToDouble(trial.settings["target_y_offset"]) * -1; // Debug.LogFormat("targetYOffset in Controller set to {0}", targetYOffset); targetHolder.transform.rotation = Quaternion.Euler(targetYOffset, targetLocation - 90, 0); //check for clamped or no cursor if (Convert.ToString(trial.settings["trial_type"]).Contains("clamped")) { handCursorObject.SetActive(false); clampedHandCursorObject.SetActive(true); //clampedHandCursorObject.GetComponent<MeshRenderer>().enabled = false; //print("setting clamped to active"); } else if (Convert.ToString(trial.settings["trial_type"]).Contains("no_cursor")) { // for no_cursor: The object has to be active (for collisions), but not visible (meshrenderer) handCursorObject.SetActive(true); handCursorObject.GetComponent <MeshRenderer>().enabled = false; clampedHandCursorObject.SetActive(false); //print("setting clamped to inactive"); } else { handCursorObject.SetActive(true); handCursorObject.GetComponent <MeshRenderer>().enabled = true; clampedHandCursorObject.SetActive(false); //print("setting clamped to inactive"); } //set the rotation for this trial // first check if this is a gradual rotation block if (Convert.ToBoolean(trial.settings["is_gradual"]) && trial.numberInBlock <= Math.Abs((Convert.ToSingle(trial.settings["rotation"])))) { // add gradualStep if positive, subtract if negative rotationAngle = (trial.numberInBlock - 1) * gradualStep * Math.Sign(Convert.ToSingle(trial.settings["rotation"])); } else { rotationAngle = Convert.ToSingle(trial.settings["rotation"]); } // set the rotation for the trial rotatorObject.transform.rotation = Quaternion.Euler(0, rotationAngle, 0); Debug.Log(rotationAngle); // explicitly convert settings["visible_cursor"] to a boolean for if statement // this is just to save in the trial by trial csv bool visibleCursor = Convert.ToBoolean(trial.settings["visible_cursor"]); trialType = Convert.ToString(trial.settings["trial_type"]); //Debug.LogFormat("the cursor is {0}", trialType); // only tilt the plane on the first trial of block if (trial.numberInBlock == 1) { // change plane settings for this trial if (Convert.ToString(trial.settings["plane_settings"]).Contains("tilt_on_x")) { StartCoroutine(planeController.SetToTiltOnX()); } else if (Convert.ToString(trial.settings["plane_settings"]).Contains("tilt_on_z")) { StartCoroutine(planeController.SetToTiltOnZ()); } else if (Convert.ToString(trial.settings["plane_settings"]).Contains("flat")) { planeController.SetToFlat(); } else { planeController.SetToNone(); } } //add these things to the trial_results csv (per trial) trial.result["trial_type"] = trial.settings["trial_type"]; trial.result["cursor_visibility"] = trial.settings["visible_cursor"]; trial.result["rotation"] = rotationAngle; trial.result["target_angle"] = targetLocation; //Create homeposition homePositionObject.SetActive(true); // turn off returnHelper returnHelper.SetActive(false); }