コード例 #1
0
    /// <summary>
    /// Performs all data collection, cleanup, and calls event to start next trial
    /// </summary>
    public void EndAndPrepare()
    {
        CurrentTask.LogParameters();

        Session.CurrentTrial.result["type"] = Session.CurrentTrial.settings.GetString("per_block_type");
        Session.CurrentTrial.result["hand"] = Session.CurrentTrial.settings.GetString("per_block_hand");

        // Track score if score tracking is enabled in the JSON
        // Defaults to disabled if property does not exist in JSON
        if (Session.settings.GetBool("exp_record_score", false))
        {
            Session.CurrentTrial.result["score"] = Score;
        }

        CursorController.UseVR = false;

        // Tracked Object logging
        foreach (string key in trackedObjects.Keys)
        {
            if (trackedObjectPath[key].Count == 0)
            {
                continue;
            }

            // Add each vector and its components separated by commas
            var list = trackedObjectPath[key];

            // For each element (Select), remove scientific notation and round to 6 decimal places.
            // Then join all these numbers separated by a comma
            Session.CurrentTrial.result[key + "_x"] =
                string.Join(",", list.Select(i => string.Format($"{i.x:F6}")));

            Session.CurrentTrial.result[key + "_y"] =
                string.Join(",", list.Select(i => string.Format($"{i.y:F6}")));

            Session.CurrentTrial.result[key + "_z"] =
                string.Join(",", list.Select(i => string.Format($"{i.z:F6}")));
        }

        // Timestamps for tracked objects
        Session.CurrentTrial.result["tracking_timestamp"] =
            string.Join(",", trackingTimestamps.Select(i => string.Format($"{i:F6}")));

        // Timestamps for when a step is incremented
        Session.CurrentTrial.result["step_timestamp"] =
            string.Join(",", StepTimer.Select(i => string.Format($"{i:F6}")));
        StepTimer.Clear();

        ClearTrackedObjects();

        // Cleanup the current task and destroy it
        BaseTask task = GetComponent <BaseTask>();

        task.Disable();

        // Make the cursor visible again, for the tasks that make it not visible
        Cursor.visible = true;

        // Re-enables tracking for next trial, in case prev trial disables it
        IsTracking = true;

        if (Session.CurrentTrial.number == Session.LastTrial.number)
        {
            Session.End();
        }
        else
        {
            Session.CurrentTrial.End();
        }

        Destroy(task);
    }