Esempio n. 1
0
        void Update()
        {
            if (trialState == TrialState.Ending)
            {
                EndTask();
                return;
            }
            else if (trialState == TrialState.Starting)
            {
                print("Starting Math");
                ShowText(trialState.Instructions());
                trialState = trialState.Next();
                return;
            }
            var finishReady        = trialState == TrialState.Ready && input.GetButtonDown("Button3");
            var finishInstructions = trialState.isInstruction() && (input.GetButtonDown("Button1") || input.GetButtonDown("Button2") || input.GetButtonDown("Button4"));
            var finishState        = (int)trialState > (int)TrialState.Ready && (int)trialState <= (int)TrialState.ITI && (trialTimer.isComplete || recorder.hasResponse);

            if (finishInstructions || finishReady || finishState)
            {
                if (finishReady)
                {
                    distractionController.gameObject.SetActive(true);
                }

                if (trialState != TrialState.Ending)
                {
                    var blockComplete = blockTimer.isComplete;
                    if (blockComplete)
                    {
                        currentBlock++;
                        if (currentBlock == NumberOfBlocks)
                        {
                            trialState = TrialState.Ending;
                            recordResults.Close();
                            return;
                        }
                        switch (type)
                        {
                        case BlockType.Easy:
                            type = BlockType.Medium;
                            break;

                        case BlockType.Medium:
                            type = BlockType.Easy;
                            break;
                        }
                        blockTimer.Start();
                    }

                    Option <TrialState> nextState = Option <TrialState> .CreateEmpty();

                    if (blockComplete || finishState || finishInstructions || finishReady)
                    {
                        if (trialState == TrialState.Problem)
                        {
                            var responses = recorder.StopRecording();
                            salienceController.addResponseResult(checker.Check(currentProblemName, responses.Count > 0 ? responses.Last().buttonPressed : null));
                            if (practice.enabled)
                            {
                                nextState = practice.HandleResponse(trialState, responses, currentProblemName);
                            }
                            else
                            {
                                var output = new TrialOutput(currentTrial, currentBlock, type, responses);
                                recordResults.WriteRow(output.ToString());
                            }
                        }
                        if (nextState.Count() > 0)
                        {
                            trialState = nextState.First();
                            if (trialState != TrialState.Correct)
                            {
                                currentTrial--;
                            }
                        }
                        else
                        {
                            trialState = trialState.Next();
                        }
                        //print ("Starting state " + trialState);

                        var instruction = trialState.Instructions();
                        if (instruction != "")
                        {
                            ShowText(instruction);
                        }
                        else
                        {
                            var currentProblem = trialState.GetTexture(type, mathTextures);
                            currentProblemName = currentProblem.name;
                            ShowImage(currentProblem);

                            trialTimer.duration = trialState.Duration();
                            if (trialState == TrialState.Problem)
                            {
                                currentTrial++;
                                recorder.StartRecording();
                            }
                            trialTimer.Start();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        void Update()
        {
            if (trialState == TrialState.Ending)
            {
                EndTask();
                return;
            }
            else if (trialState == TrialState.Starting)
            {
                print("Starting AX-CPT");
                ShowText(trialState.Instructions(textures));
                trialState = trialState.Next();
                return;
            }
            var finishReady        = trialState == TrialState.Ready && input.GetButtonDown("Button3");
            var finishInstructions = trialState.isInstruction() && input.IsAnyKeyDown();
            var finishState        = (int)trialState > (int)TrialState.Ready && (int)trialState <= (int)TrialState.Probe && timer.isComplete;

            if (finishInstructions || finishReady || finishState)
            {
                if (finishReady)
                {
                    distractionController.gameObject.SetActive(true);
                }

                Option <TrialState> nextState = Option <TrialState> .CreateEmpty();

                if (recorder.isRecording && (trialState == TrialState.ISI || trialState == TrialState.PreCueITI))
                {
                    var responses = recorder.StopRecording();
                    salienceController.addResponseResult(trialList.trialTypes[currentTrial].CheckResponse(trialState, responses.Count > 0 ? responses.Last().buttonPressed : null));
                    if (practice.enabled)
                    {
                        nextState = practice.HandleResponse(trialState, responses, trialList.trialTypes[currentTrial]);
                    }
                    else
                    {
                        var output = new TrialOutput(currentTrial, trialList.trialTypes[currentTrial], trialState, stimulusName, responses);
                        recordResults.WriteRow(output.ToString());
                    }
                }

                if (trialState == TrialState.PreCueITI && nextState.Count() == 0)
                {
                    currentTrial++;
                    if (currentTrial == trialList.trialTypes.Length)
                    {
                        trialState = TrialState.Ending;
                        recordResults.Close();
                        return;
                    }
                }

                if (nextState.Count() > 0)
                {
                    trialState = nextState.First();
                    if (trialState != TrialState.Correct)
                    {
                        // Repeat the current trial
                        currentTrial--;
                    }
                }
                else
                {
                    if (trialState == TrialState.Correct)
                    {
                        if (practice.PreviousState == TrialState.ISI)
                        {
                            trialState = TrialState.PreProbeITI;
                        }
                        else
                        {
                            trialState = TrialState.PreCueITI;
                        }
                    }
                    else
                    {
                        trialState = trialState.Next();
                    }
                }
                //print ("Starting state " + trialState + " in trial number " + currentTrial);

                var instruction = trialState.Instructions(textures);
                if (instruction != "")
                {
                    ShowText(instruction);
                }
                else
                {
                    // currentTrial will be -1 on the first precueiti state when we need to show the iti texture
                    // in that case, using null is okay for trial type because the iti texture doesn't depend on the trial type.
                    var trialType       = currentTrial == -1 ? null : trialList.trialTypes [currentTrial];
                    var selectedTexture = trialState.GetTexture(trialType, textures);
                    ShowImage(selectedTexture);

                    timer.duration = trialState.Duration();
                    if (trialState == TrialState.Cue || trialState == TrialState.Probe)
                    {
                        stimulusName = selectedTexture.name;
                        recorder.StartRecording();
                    }
                    timer.Start();
                }
            }
        }
Esempio n. 3
0
        void Update()
        {
            if (trialState == TrialState.Ending)
            {
                EndTask();
                return;
            }
            else if (trialState == TrialState.Starting)
            {
                print("Starting Verbal Stroop");
                ShowText(trialState.Instructions());
                trialState = trialState.Next();
                return;
            }
            var finishReady        = trialState == TrialState.Ready && input.GetButtonDown("Button3");
            var finishInstructions = trialState.isInstruction() && (input.GetButtonDown("Button1") || input.GetButtonDown("Button2") || input.GetButtonDown("Button4"));
            var finishState        = (int)trialState > (int)TrialState.Ready && (int)trialState <= (int)TrialState.ITI && timer.isComplete;

            if (finishInstructions || finishReady || finishState)
            {
                if (finishReady)
                {
                    distractionController.gameObject.SetActive(true);
                }

                Option <TrialState> nextState = Option <TrialState> .CreateEmpty();

                if (recorder.isRecording && trialState == TrialState.ITI)
                {
                    var responses = recorder.StopRecording();
                    salienceController.addResponseResult(trialList.trialProperties[currentTrial].CheckResponse(responses.Count > 0 ? responses.Last().buttonPressed : null));
                    if (practice.enabled)
                    {
                        nextState = practice.HandleResponse(trialState, responses, trialList.trialProperties[currentTrial]);
                    }
                    else
                    {
                        var output = new TrialOutput(currentTrial, trialList.trialProperties[currentTrial], responses);
                        recordResults.WriteRow(output.ToString());
                    }
                }
                if (trialState == TrialState.ITI && nextState.Count() == 0)
                {
                    currentTrial++;
                    if (currentTrial == trialList.trialProperties.Length)
                    {
                        trialState = TrialState.Ending;
                        recordResults.Close();
                        return;
                    }
                }

                if (nextState.Count() > 0)
                {
                    trialState = nextState.First();
                    if (trialState != TrialState.Correct)
                    {
                        currentTrial--;
                    }
                }
                else
                {
                    trialState = trialState.Next();
                }
                //print ("Starting state " + trialState + " in trial number " + currentTrial);

                var instruction = trialState.Instructions();
                if (instruction != "")
                {
                    ShowText(instruction);
                }
                else
                {
                    switch (trialState)
                    {
                    case TrialState.Word:
                        avatar.Play(trialList.trialProperties [currentTrial].sound);
                        var trialProps = trialList.trialProperties [currentTrial];
                        ShowColorText(trialProps.text.ToString(), trialProps.color.GetColor());
                        break;

                    case TrialState.ITI:
                        ShowImage(textures.iti);
                        break;
                    }
                    timer.duration = trialState.Duration();
                    if (trialState == TrialState.Word)
                    {
                        recorder.StartRecording();
                    }
                    timer.Start();
                }
            }
        }